Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Default values for SiteConfig extension


Go to End


3 Posts   1812 Views

Avatar
aragonne

Community Member, 26 Posts

9 December 2010 at 10:57pm

Hi

Does anyone know how to set default values for the site config fields ... similar to:

static $defaults = array (...);

for DataObjects?

I tried using static $defaults in my SiteConfig extension but the values didn't get set.

class CustomSiteConfig extends DataObjectDecorator {


    /**
     * Defines the additional site configuration fields
     *
     * @return array
     */
    function extraStatics() {
        return array(
            'db' => array(
                'IsDisplayTestAskUs' => 'Boolean'
                , 'IsDisplayFooterHoncode' => 'Boolean'
            ),
    }


    /**
     * Displays the edit fields in the CMS
     *
     * @param FieldSet $fields
     */
    public function updateCMSFields( $fields ) {
         $fields->addFieldToTab( 'Root.Main', new CheckboxField( 'IsDisplayTestAskUs', 'Display Test Ask Us') );
         $fields->addFieldToTab( 'Root.Main', new CheckboxField( 'IsDisplayFooterHoncode', 'Display Footer HON code') );
    }


    // not sure if this will work with SiteConfig fields
    static $defaults = array (
        'IsDisplayTestAskUs' => true
        , 'IsDisplayFooterHoncode' => true
    );
}

Thanks!

Avatar
Willr

Forum Moderator, 5523 Posts

10 December 2010 at 12:14pm

Because you are dealing with an extension (i.e the SiteConfig::$defaults won't call your static) you need to use the extension class extraStatics (like you have) and include the defaults there.

function extraStatics() { 
return array( 
'db' => array( 
'IsDisplayTestAskUs' => 'Boolean' , 
'IsDisplayFooterHoncode' => 'Boolean' 
),
'defaults' => array(
'IsDisplayTestAskUs' => true
)); 
}

Avatar
aragonne

Community Member, 26 Posts

10 December 2010 at 12:37pm


Thanks Willr! That did the trick.