We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29597 ☆ A M B ☆
    • 350 Posts
    Thanks for all the suggestions, but I still am unable to get more then one setting...
    Would be great if anybody could post the code I need... (or a other working example of getting Client Config settings set in a package)

    Totally stuck with this.
      MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
      DESIGNfromWITHIN, MPThemes and Any Screen Size
      Follow me on Twitter | Read my blog | My code on GitHub
      • 3749
      • 24,544 Posts
      See if this works:

      ?php
      /** Array of ClientConfig settings for Flexibility package
       * @package flexibility
       * @subpackage build
       */
       
      $mySettings = array();
       
      $modelPath = $modx->getOption('clientconfig.core_path',null,$modx->getOption('core_path').'components/clientconfig/').'model/';
      $modx->addPackage('clientconfig',$modelPath);
       
      $mySettings[1]= $modx->newObject('cgGroup');
      $mySettings[1]->fromArray(array (
          'id' => '1',
          'label' => 'Site settings',
          'description' => 'General settings for the site',
      ), '', true, true);
        
      $groupSettings = array();
      $groupSettings[1] = $modx->newObject('cgSetting');
      $groupSettings[1]->fromArray(array (
          'id' => 1,
          'key' => 'footer_text',
          'title' => 'Footer text',
          'description' => 'Content of the footer text',
          'value' => 'This is the default footer text',
          'xtype' => 'textfield',
          'group' => '1',
      ), '', true, true);
       
      $groupSettings[2] = $modx->newObject('cgSetting');
      $groupSettings[2]->fromArray(array (
          'id' => 2,
          'key' => 'flex-4-header-logo',
          'title' => 'Header logo',
          'description' => 'Main logo for your website',
          'value' => '',
          'xtype' => 'source',
          'group' => '1',
      ), '', true, true);
       
      $groupSettings[3] = $modx->newObject('cgSetting');
      $groupSettings[3]->fromArray(array (
          'id' => 3,
          'key' => 'flex-4-header-logo-alt',
          'title' => 'Header logo alt text',
          'description' => 'The alt text for the main logo of your website (e.g. company logo)',
          'value' => '',
          'xtype' => 'textfield',
          'group' => '1',
      ), '', true, true);
       
      $groupSettings[4] = $modx->newObject('cgSetting');
      $groupSettings[4]->fromArray(array (
          'id' => 4,
          'key' => 'flex-4-header-logo-link-id',
          'title' => 'Homepage page ID',
          'description' => 'Page ID of the header logo link (default = 1)',
          'value' => '1',
          'xtype' => 'textfield',
          'group' => '1',
      ), '', true, true);
       
      $groupSettings[5] = $modx->newObject('cgSetting');
      $groupSettings[5]->fromArray(array (
          'id' => 5,
          'key' => 'flex-4-header-logo-link-title',
          'title' => 'Header logo link title',
          'description' => 'Title of the logo link',
          'value' => '',
          'xtype' => 'textfield',
          'group' => '1',
      ), '', true, true);
       
      $mySettings[1]->addMany($groupSettings);
        
      return $mySettings;


      These are not System Settings, BTW, these are ClientConfig objects.



        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
        • 29597 ☆ A M B ☆
        • 350 Posts
        Nope... This does not even add anything...

        $mySettings = array();
          
        $modelPath = $modx->getOption('clientconfig.core_path',null,$modx->getOption('core_path').'components/clientconfig/').'model/';
        $modx->addPackage('clientconfig',$modelPath);
          
        $mySettings[1]= $modx->newObject('cgGroup');
        $mySettings[1]->fromArray(array (
            'id' => '1',
            'label' => 'Site settings',
            'description' => 'General settings for the site',
        ), '', true, true);
           
        $groupSettings = array();
        $groupSettings[1] = $modx->newObject('cgSetting');
        $groupSettings[1]->fromArray(array (
            'id' => 1,
            'key' => 'footer_text',
            'title' => 'Footer text',
            'description' => 'Content of the footer text',
            'value' => 'This is the default footer text',
            'xtype' => 'textfield',
            'group' => '1',
        ), '', true, true);
          
        $groupSettings[2] = $modx->newObject('cgSetting');
        $groupSettings[2]->fromArray(array (
            'id' => 2,
            'key' => 'flex-4-header-logo',
            'title' => 'Header logo',
            'description' => 'Main logo for your website',
            'value' => '',
            'xtype' => 'source',
            'group' => '1',
        ), '', true, true);
          
        $groupSettings[3] = $modx->newObject('cgSetting');
        $groupSettings[3]->fromArray(array (
            'id' => 3,
            'key' => 'flex-4-header-logo-alt',
            'title' => 'Header logo alt text',
            'description' => 'The alt text for the main logo of your website (e.g. company logo)',
            'value' => '',
            'xtype' => 'textfield',
            'group' => '1',
        ), '', true, true);
          
        $groupSettings[4] = $modx->newObject('cgSetting');
        $groupSettings[4]->fromArray(array (
            'id' => 4,
            'key' => 'flex-4-header-logo-link-id',
            'title' => 'Homepage page ID',
            'description' => 'Page ID of the header logo link (default = 1)',
            'value' => '1',
            'xtype' => 'textfield',
            'group' => '1',
        ), '', true, true);
          
        $groupSettings[5] = $modx->newObject('cgSetting');
        $groupSettings[5]->fromArray(array (
            'id' => 5,
            'key' => 'flex-4-header-logo-link-title',
            'title' => 'Header logo link title',
            'description' => 'Title of the logo link',
            'value' => '',
            'xtype' => 'textfield',
            'group' => '1',
        ), '', true, true);
          
        $mySettings[1]->addMany($groupSettings);
           
        return $mySettings;


        in Build transport:

        /* load system settings */
        if ($hasSettings) {
            $settings = include $sources['data'].'transport.settings.php';
            if (!is_array($settings)) {
                $modx->log(modX::LOG_LEVEL_ERROR,'Could not package in settings.');
            } else {
                $attributes= array(
                    xPDOTransport::UNIQUE_KEY => 'label',
                    xPDOTransport::PRESERVE_KEYS => true,
                    xPDOTransport::UPDATE_OBJECT => false,
                    xPDOTransport::RELATED_OBJECTS => true,
                    xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
                        'Settings' => array(
                            xPDOTransport::PRESERVE_KEYS => true,
                            xPDOTransport::UPDATE_OBJECT => false,
                            xPDOTransport::UNIQUE_KEY => 'key',
                        ),
                    ),
                );
                foreach ($settings as $setting) {
                    $vehicle = $builder->createVehicle($setting,$attributes);
                    $builder->putVehicle($vehicle);
                }
                $modx->log(modX::LOG_LEVEL_INFO,'Packaged in '.count($settings).' System Settings.');
                unset($settings,$setting,$attributes);
            }
        }
          MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
          DESIGNfromWITHIN, MPThemes and Any Screen Size
          Follow me on Twitter | Read my blog | My code on GitHub
          • 3749
          • 24,544 Posts
          Is the build not reporting the setting as added, or are the objects just not installed when you install the package?
            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
            • 29597 ☆ A M B ☆
            • 350 Posts
            The build reports to add one setting only, after install just one setting is added....

            I am resorting to setting 'normal' system settings for now, hope to be able to add Client Config setting by default later on...
              MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
              DESIGNfromWITHIN, MPThemes and Any Screen Size
              Follow me on Twitter | Read my blog | My code on GitHub
              • 3749
              • 24,544 Posts
              You are only transporting one setting, so that report is accurate. That setting is carrying with it the related objects (which are cgSetting objects).

              I have had trouble with Package Manager when trying to add related objects if the parent object is nested under a category. It has trouble with nesting levels more than one level deep.

              That's why MyComponent installs all related objects in resolvers. It's also why in a lot of packages with plugins (which have plugin events as related objects) the plugin has no category.

              I don't think MC would handle these custom objects automatically. You'd need to do it yourself in a custom resolver.



                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
                • 41406 ☆ A M B ☆
                • 30 Posts
                Are there any entries in the error log on the installation modx? am thinking it might not have loaded/installed the client config models before it runs the vehicle...
                  • 3749
                  • 24,544 Posts
                  Quote from: alanpich at May 21, 2013, 12:54 AM
                  Are there any entries in the error log on the installation modx? am thinking it might not have loaded/installed the client config models before it runs the vehicle...

                  He's running addPackage() for them. In theory, loadClass() is called automatically when newObject() is called.
                    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