[{"name":"type","desc":"Type of SVG","xtype":"textfield","options":[],"value":"bookmark","lexicon":"","overridden":2,"desc_trans":"Type of SVG","area":"LudwigQRcode","area_trans":"LudwigQRcode","menu":null},{"name":"width","desc":"Width of SVG","xtype":"numberfield","options":[],"value":"100","lexicon":"","overridden":2,"desc_trans":"Width of SVG","area":"LudwigQRcode","area_trans":"LudwigQRcode","menu":null}] [{"name":"type","desc":"QR-Code type","xtype":"textfield","options":[],"value":"email","lexicon":"","overridden":2,"desc_trans":"QR-Code type","area":"LudwigQRcode","area_trans":"LudwigQRcode","menu":null},{"name":"width","desc":"Width of QR-Code","xtype":"numberfield","options":[],"value":"100","lexicon":"","overridden":2,"desc_trans":"Width of QR-Code","area":"LudwigQRcode","area_trans":"LudwigQRcode","menu":null}]
$i = 0; $chunks[$i]= $modx->newObject('modChunk'); $chunks[$i]->fromArray(array( 'id' => $i, 'name' => 'qrcode', 'description' => 'Generate QR-Codes', 'snippet' => file_get_contents($sources['chunks'].'qrcode.chunk.tpl'), 'properties' => '', ),'',true,true);
This question has been answered by BobRay. See the first response.
$properties = 'JSON string here';
'properties' = $modx->fromJSON($properties);
include_once( $sources['chunks'].'qrcode.chunk.propertysets.tpl' ); $i = 0; $chunks[$i]= $modx->newObject('modChunk'); $chunks[$i]->fromArray(array( 'id' => $i, 'name' => 'qrcode', 'description' => 'Generate QR-Codes', 'snippet' => file_get_contents($sources['chunks'].'qrcode.chunk.tpl'), 'properties' => getChunkPropertySet(), ),'',true,true); return $chunks;
function getChunkPropertySet() { global $modx; // Define the Properties in JSON (exported from Modx) $data= array(); $data['sms'] = '[{"name":"type","desc":"Set a type","xtype":"textfield","options":[],"value":"sms","lexicon":"","overridden":2,"desc_trans":"Set a type","area":"LudwigQRcode","area_trans":"LudwigQRcode","menu":null},{"name":"width","desc":"Width of SVG","xtype":"numberfield","options":[],"value":"100","lexicon":"","overridden":2,"desc_trans":"Width of SVG","area":"LudwigQRcode","area_trans":"LudwigQRcode","menu":null}]'; return( $modx->fromJSON($data['sms']) ); }
$data= array(); $data['sms'] = '['name':'firstset', 'description':'Jup', 'setme':{"name":"type","desc":"Set a type","xt.... }];
<?php /** * propertySets transport file for Example extra * * Copyright 2013 by Bob Ray <http://bobsguides.com> * Created on 06-09-2013 * * @package example * @subpackage build */ if (! function_exists('stripPhpTags')) { function stripPhpTags($filename) { $o = file_get_contents($filename); $o = str_replace('<' . '?' . 'php', '', $o); $o = str_replace('?>', '', $o); $o = trim($o); return $o; } } /* @var $modx modX */ /* @var $sources array */ /* @var xPDOObject[] $propertySets */ $propertySets = array(); $propertySets[1] = $modx->newObject('modPropertySet'); $propertySets[1]->fromArray(array ( 'id' => 1, 'name' => 'PropertySet1', 'description' => 'Description for PropertySet1', 'properties' => NULL, ), '', true, true); $propertySets[2] = $modx->newObject('modPropertySet'); $propertySets[2]->fromArray(array ( 'id' => 2, 'name' => 'PropertySet2', 'description' => 'Description for PropertySet2', 'properties' => NULL, ), '', true, true); return $propertySets; [/code
You could add properties to the property sets as you did above.
If you need to connect the property set to an element, you can do it with addMany(), or create the modElementPropertySet intersect object directly in a resolver.
http://bobsguides.com/modx-object-quick-reference.html#modElementPropertySet
BTW, my book (see my sig.) has information on the difference between default properties and property sets and how to deal with them in code, along with a lot of other stuff.