We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20197
    • 9 Posts
    Hi,

    I've a question about properties set and Modx packaging. I created an chunk with some property sets and exported them e.g.:

    [{"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}]
    


    Now I want to link these sets to the right chunk in transport.chunks.php:

    $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);
    


    How can I realize it to link json/object/array property set to modChunk?

    Thank you very much for your help!

    Thomas

    This question has been answered by BobRay. See the first response.

      • 3749
      • 24,544 Posts
      You can do it, but I think you'd have to convert them from JSON to a PHP array. I'm not sure if you're referring to the chunk's default properties, or to a separate property set. For default properties, it would look like this:

      $properties = 'JSON string here';


      Then in the chunk fields:

      'properties' = $modx->fromJSON($properties);


      You might look at MyComponent, which lets you create the default properties or property sets in MODX and automatically exports them to the _build files.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 20197
        • 9 Posts
        Ahoi BobRay,

        it works to generate some properties (in standard set) for a chunk but not for a complete property set. I did the following:

        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;
        



        And the propertysets.tpl looks like this:

        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']) );
        }
        


        I have the feeling that something like:
                $data= array();
                $data['sms'] = '['name':'firstset', 'description':'Jup', 'setme':{"name":"type","desc":"Set a type","xt.... }];
        

        should work. But I cant find something in the documentation.

        • discuss.answer
          • 3749
          • 24,544 Posts
          That's because a property set (as opposed to an element or resource's default properties) is a separate, independent object. You need to create a modPropertySet object.

          This is from the MyComponent example project:

          <?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.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 20197
            • 9 Posts
            Hi BobRay,

            thank you very much for geat support!

            These propertysets were to complicated in combination with the installer for me. I wanted to use chunk->snippet but I changed back to snippet -> chunk. So I don't need ps not anymore.

            Cheers,

            Thomas