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
    I'm so stuck why does this not work?

    transport.settings.php:

    <?php
    /** Array of system settings for Flexibility package
     * @package flexibility
     * @subpackage build
     */
    
    
    /* This section is ONLY for new System Settings to be added to
     * The System Settings grid. If you include existing settings,
     * they will be removed on uninstall. Existing setting can be
     * set in a script resolver (see install.script.php).
     */
    $settings = array();
    
    /* The first three are new settings */
    $modelPath = $modx->getOption('clientconfig.core_path',null,$modx->getOption('core_path').'components/clientconfig/').'model/';
                $modx->addPackage('clientconfig',$modelPath);
    
    $settings['group']= $modx->newObject('cgGroup');
    $settings['group']->fromArray(array (
        'id' => '1',
        'label' => 'Site settings',
        'description' => 'General settings for the site',
    ), '', true, true);
     
    $groupSettings = array();
    $groupSettings['footerText'] = $modx->newObject('cgSetting');
    $groupSettings['footerText']->fromArray(array (
        '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['flex-4-header-logo'] = $modx->newObject('cgSetting');
    $groupSettings['flex-4-header-logo']->fromArray(array (
        'key' => 'flex-4-header-logo',
        'title' => 'Header logo',
        'description' => 'Main logo for your website',
        'value' => '',
        'xtype' => 'image',
        'group' => '1',
    ), '', true, true);
    
    $groupSettings['flex-4-header-logo-alt'] = $modx->newObject('cgSetting');
    $groupSettings['flex-4-header-logo-alt']->fromArray(array (
        '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['flex-4-header-logo-link-id'] = $modx->newObject('cgSetting');
    $groupSettings['flex-4-header-logo-link-id']->fromArray(array (
        '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['flex-4-header-logo-link-title'] = $modx->newObject('cgSetting');
    $groupSettings['flex-4-header-logo-link-title']->fromArray(array (
        '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);
     
    $settings['group']->addMany($groupSettings);
     
    return $settings;


    Code in build.transport.php:

    /* 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
      • 22303 MODX Staff
      • 10,725 Posts
      It may be because you are using the variable $settings to capture the include return from a variable called $settings... ?
        • 29597 ☆ A M B ☆
        • 350 Posts
        Could you explain a bit more what you mean? I am so bad at PHP...
          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
          • 41406 ☆ A M B ☆
          • 30 Posts
          I think opengeek means that you should rename the $settings variable in your transport.settings.php file.

          By having a variable called $settings in both files (which by using the include command end up in the same scope) it may be causing confusion over which one it is referring to.

          try renaming $settings to $sysSettings in one (but not both) of the files
            • 38290
            • 712 Posts
            Don't feel bad everybody is bad at php
              jpdevries
              • 29597 ☆ A M B ☆
              • 350 Posts
              Thanks, makes sense but I am not sure if I do it right.
              This is not working:

              /* 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);
                  }
              }


              <?php
              /** Array of system settings for Flexibility package
               * @package flexibility
               * @subpackage build
               */
              
              
              /* This section is ONLY for new System Settings to be added to
               * The System Settings grid. If you include existing settings,
               * they will be removed on uninstall. Existing setting can be
               * set in a script resolver (see install.script.php).
               */
              $settings = array();
              
              /* The first three are new settings */
              $modelPath = $modx->getOption('clientconfig.core_path',null,$modx->getOption('core_path').'components/clientconfig/').'model/';
                          $modx->addPackage('clientconfig',$modelPath);
              
              $settings['group']= $modx->newObject('cgGroup');
              $settings['group']->fromArray(array (
                  'id' => '1',
                  'label' => 'Site settings',
                  'description' => 'General settings for the site',
              ), '', true, true);
               
              $groupSettings = array();
              $groupSettings['footerText'] = $modx->newObject('cgSetting');
              $groupSettings['footerText']->fromArray(array (
                  '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['flex-4-header-logo'] = $modx->newObject('cgSetting');
              $groupSettings['flex-4-header-logo']->fromArray(array (
                  'key' => 'flex-4-header-logo',
                  'title' => 'Header logo',
                  'description' => 'Main logo for your website',
                  'value' => '',
                  'xtype' => 'source',
                  'group' => '1',
              ), '', true, true);
              
              $groupSettings['flex-4-header-logo-alt'] = $modx->newObject('cgSetting');
              $groupSettings['flex-4-header-logo-alt']->fromArray(array (
                  '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['flex-4-header-logo-link-id'] = $modx->newObject('cgSetting');
              $groupSettings['flex-4-header-logo-link-id']->fromArray(array (
                  '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['flex-4-header-logo-link-title'] = $modx->newObject('cgSetting');
              $groupSettings['flex-4-header-logo-link-title']->fromArray(array (
                  '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);
              
              $settings['group']->addMany($groupSettings);
               
              return $settings;
              [ed. note: ThaClown last edited this post 13 years, 5 months ago.]
                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
                • 41406 ☆ A M B ☆
                • 30 Posts
                even after changing the $settings var?
                  • 29597 ☆ A M B ☆
                  • 350 Posts
                  Yea... no settings are added.. it does compile.
                    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
                    • 22303 MODX Staff
                    • 10,725 Posts
                    You didn't change the $settings variable in your include in your latest post. The variable is still $settings and is still being assigned to $settings from your include. Not that this is the problem for sure.... [ed. note: opengeek last edited this post 13 years, 5 months ago.]
                      • 33983 ☆ A M B ☆
                      • 181 Posts
                      Without seeing all the code here is my guess. I think you are using the System Settings resolver to try to add custom DB settings that are for Client Config. I would suggest that you add these custom DB rows on tables.resolver.php assuming you are using My Component: http://modx.com/extras/package/mycomponent or similar. Note I have not used version 3 but the previous version of My Component so it might be labeled differently.