@@ -39,13 +39,16 @@ final class RenderResource
39
39
/** @var array */
40
40
public $ data = [];
41
41
42
+ /** @var array */
43
+ public $ pageSettings = [];
44
+
42
45
/** @var array */
43
46
private $ elementOptions = [];
44
47
45
48
/** @var array */
46
49
private $ elementCache = [];
47
50
48
- public function __construct (modResource $ resource , modX $ modx , $ data = [])
51
+ public function __construct (modResource $ resource , modX $ modx , $ data = [], $ pageSettings = [] )
49
52
{
50
53
$ this ->resource = $ resource ;
51
54
$ this ->modx = $ modx ;
@@ -60,6 +63,7 @@ public function __construct(modResource $resource, modX $modx, $data = [])
60
63
if (empty ($ this ->data ) && !empty ($ this ->resource ->content )) {
61
64
$ this ->setDefaults ();
62
65
}
66
+ $ this ->pageSettings = $ pageSettings ;
63
67
$ elements = [];
64
68
$ this ->gatherElements ($ elements , $ this ->data );
65
69
@@ -213,7 +217,6 @@ public function render(): bool
213
217
214
218
$ c ->where (
215
219
[
216
- 'type ' => 'freddropzone ' ,
217
220
'TemplateVarTemplates.templateid ' => $ this ->resource ->get ('template ' ),
218
221
]
219
222
);
@@ -224,24 +227,29 @@ public function render(): bool
224
227
$ mTypes = explode (', ' , $ mTypes );
225
228
foreach ($ tvs as $ tv ) {
226
229
$ tvName = $ tv ->get ('name ' );
227
-
228
- if (isset ($ this ->data [$ tvName ])) {
230
+ // check if TV is in base data or pageSettings
231
+ $ tvValue = (isset ($ this ->pageSettings ['tvs ' ][$ tvName ])) ?
232
+ $ this ->pageSettings ['tvs ' ][$ tvName ] :
233
+ ($ this ->data [$ tvName ] ?? null );
234
+ if (isset ($ tvValue )) {
229
235
$ tvContent = '' ;
230
-
231
- foreach ($ this ->data [$ tvName ] as $ item ) {
232
- try {
233
- $ tvContent .= $ this ->renderElement (
234
- $ this ->twig ->render (
235
- $ item ['widget ' ],
236
- $ this ->mergeSetting (!empty ($ item ['elId ' ]) ? $ item ['elId ' ] : '' , $ item ['settings ' ])
237
- ),
238
- $ item ,
239
- true
240
- );
241
- } catch (\Exception $ e ) {
236
+ if ($ tv ->type === 'freddropzone ' || is_array ($ tvValue )) {
237
+ foreach ($ tvValue as $ item ) {
238
+ try {
239
+ $ tvContent .= $ this ->renderElement (
240
+ $ this ->twig ->render (
241
+ $ item ['widget ' ],
242
+ $ this ->mergeSetting (!empty ($ item ['elId ' ]) ? $ item ['elId ' ] : '' , $ item ['settings ' ])
243
+ ),
244
+ $ item ,
245
+ true
246
+ );
247
+ } catch (\Exception $ e ) {
248
+ }
242
249
}
250
+ } else {
251
+ $ tvContent = $ tvValue ;
243
252
}
244
-
245
253
$ tvContent = Utils::htmlDecodeTags ($ tvContent , $ parser );
246
254
if (in_array ($ tv ->type , $ mTypes , true )) {
247
255
$ this ->resource ->setTVValue ($ tvName , $ this ->reversePreparedOutput ($ tv , $ tvContent , $ this ->resource ));
0 commit comments