Jump to:

22976 Posts in 11719 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Default values for SiteConfig extension

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

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

Page: 1
Go to End
Author Topic: 1014 Views
  • aragonne
    Avatar
    Community Member
    26 Posts

    Default values for SiteConfig extension Link to this post

    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!

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Default values for SiteConfig extension Link to this post

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

  • aragonne
    Avatar
    Community Member
    26 Posts

    Re: Default values for SiteConfig extension Link to this post

    Thanks Willr! That did the trick.

    1014 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.