[ {"caption":"Info", "fields": [ {"field":"date","caption":"Date","inputTVtype":"date"}, {"field":"change","caption":"Change","inputTVtype":"textarea"} ]} ]
[ {"caption":"Info", "fields": [ {"field":"date","caption":"Date","inputTVtype":"date"}, {"field":"change","caption":"Change","inputTVtype":"textarea"}, {"field":"resource-id","caption":"Resource ID","inputTVtype":"text"} ]} ]
<?php // copied from here https://forums.modx.com/thread/?thread=41006&page=20 // [[mergeMIGX? &tvname=`mymigxtv` &docids=`10,11,12` &tpl=`mytpl` &debug=`1`]] $docids = explode(',', $docids); if ($tv = $modx->getObject('modTemplateVar', array('name' => $tvname))) { $allitems = array(); foreach ($docids as $docid) { $outputvalue = $tv->renderOutput($docid); $items = $modx->fromJSON($outputvalue); if (is_array($items)) { $allitems = array_merge($allitems, $items); } elseif ($debug) { echo 'Error in '.$docid.':'.$outputvalue; } } $scriptProperties['value'] = $modx->toJSON($allitems); } return $modx->runSnippet('getImageList', $scriptProperties);
This question has been answered by Bruno17. See the first response.
$tvname = 'yourMIGXtv'; $items = json_decode($resource->getTVValue($tvname),true); $newitems = array(); if (is_array($items)){ foreach($items as $item){ $item['resource_id'] = $resource->get('id'); $newitems[] = $item; } $resource->setTVValue($tvname,json_encode($newitems)); }