user805528
user805528

Reputation: 301

Sliverstripe CMS populate dropdown with enum values

I need two additional fields for general settings (TimeForClosingTab, ClosingTabOnOff). I get the fields but I don't know how to populate the enum field correctly. The file is in app/src/extensions. What would be the correct way to define the class in singleton?

CustomSiteConfig.php

class CustomSiteConfig extends DataExtension
{

private static $db = [
    'TimeForClosingTab' => 'Int',
    'ClosingTabOnOff' => "Enum(array('On','Off'))"
];

public function updateCMSFields(FieldList $fields)
{
    $fields->addFieldToTab("Root.Main",
        new \SilverStripe\Forms\NumericField("TimeForClosingTab", "Time before closing new tab (s)"),
        new \SilverStripe\Forms\DropdownField('ClosingTabOnOff', 'Turn closing tab on / off',
            singleton('CustomSiteConfig')->dbObject('ClosingTabOnOff')->enumValues())
    );
}

}

yaml:

Silverstripe\SiteConfig\SiteConfig:
  extensions:
    - CustomSiteConfig

Upvotes: 0

Views: 91

Answers (1)

user805528
user805528

Reputation: 301

The answer was in the yml :)

singleton('\Silverstripe\SiteConfig\SiteConfig')->dbObject('ClosingTabOnOff')->enumValues())

Upvotes: 1

Related Questions