PluginProbe
Depicter — Popup & Slider Builder / 1.9.2
Depicter — Popup & Slider Builder v1.9.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
← All changes | app/src/Document/Models/Traits/HasDataSheetTrait.php +23 -23 1.3.0 → 1.9.2 View file →
@@ -9,9 +9,9 @@
9 9 * Only available if dataSource is assigned to the section
10 10 *
11 11 * @var array|null
12 12 */
13 - protected $dataSheet;
13 + protected $dataSheet = [];
14 14
15 15
16 16 /**
17 17 * Retrieves the dataSource record (dataSheet)
@@ -45,9 +45,16 @@
45 45 *
46 46 * @return string
47 47 */
48 48 public function getDataSheetID() {
49 - return $this->dataSheet['{{{uuid}}}'] ?? '';
49 + if( $dataSheet = $this->getDataSheet() ){
50 + if( !empty( $dataSheet['id'] ) ){
51 + return $dataSheet['id'];
52 + } elseif( !empty( $dataSheet['uuid'] ) ){
53 + return $dataSheet['uuid'];
54 + }
55 + }
56 + return $this->maybeReplaceDataSheetTags('{{{uuid}}}', '' );
50 57 }
51 58
52 59 /**
53 60 * Retrieves data tag value if exists
@@ -56,9 +63,9 @@
56 63 *
57 64 * @return mixed|string
58 65 */
59 66 public function getDataSheetTagValue( $tag ) {
60 - return $this->dataSheet[ $tag ] ?? '';
67 + return $this->hasDataSheet() ? \Depicter::dataSource()->tagsManager()->convert( $tag, $this->getDataSheet() ) : '';
61 68 }
62 69
63 70 /**
64 71 * Retrieves url of this dataSheet
@@ -65,9 +72,14 @@
65 72 *
66 73 * @return string
67 74 */
68 75 public function getDataSheetUrl() {
69 - return $this->dataSheet[ '{{{url}}}' ] ?? '';
76 + if( $dataSheet = $this->getDataSheet() ){
77 + if( !empty( $dataSheet['url'] ) ){
78 + return $dataSheet['url'];
79 + }
80 + }
81 + return $this->maybeReplaceDataSheetTags('{{{url}}}', '');
70 82 }
71 83
72 84 /**
73 85 * Whether section is linked to corresponding dataSheet or not
@@ -74,9 +86,9 @@
74 86 *
75 87 * @return false
76 88 */
77 89 public function isLinkedToDataSheet(){
78 - return $this->dataSheet[ '{{{linkSlides}}}' ] ?? false;
90 + return $this->maybeReplaceDataSheetTags('{{{linkSlides}}}', false);
79 91 }
80 92
81 93 /**
82 94 * Replace dataSheets tags if exits
@@ -81,31 +93,19 @@
81 93 /**
82 94 * Replace dataSheets tags if exits
83 95 *
84 96 * @param $variable
97 + * @param $default
85 98 *
86 99 * @return array|mixed|string|string[]
87 100 */
88 - protected function maybeReplaceDataSheetTags( $variable ){
101 + protected function maybeReplaceDataSheetTags( $variable, $default = null, $args = [] ){
89 102 if( $dataSheet = $this->getDataSheet() ){
90 - return str_replace( array_keys( $dataSheet ), $dataSheet, $variable );
103 + $dataSheet = !empty( $args ) ? array_merge( $dataSheet, $args ) : $dataSheet;
104 + return \Depicter::dataSource()->tagsManager()->convert( $variable, $dataSheet );
91 105 }
92 - return $variable;
93 - }
94 -
95 - /**
96 - * Replace dataSheets tags if exits
97 - *
98 - * @param string $variable
99 - * @param string $tag
100 - *
101 - * @return string
102 - */
103 - protected function maybeReplaceDataSheetTag( $variable, $tag = '' ){
104 - if( $dataSheet = $this->getDataSheet() ){
105 - if( !empty( $dataSheet[ $tag ] ) ){
106 - return str_replace( $tag, $dataSheet[ $tag ], $variable );
107 - }
106 + if( ! is_null( $default ) ){
107 + return $default;
108 108 }
109 109 return $variable;
110 110 }
111 111 }