I'm trying to add a DropdownField to the main site options just below the 'Themes' field. The idea is to have multiple colour schemes for a particular theme, and the DropdownField will select a different .css file to use to style the site.
I had this working fine on a page by page basis (thanks to this tutorial: http://goo.gl/cuQuh ) by adding the following code to the Page class:
public static $db = array(
..
"ColourSchemes" => "Enum('Red, Green, Blue', 'Red')",
);
..
function getCMSFields() {
$fields = parent::getCMSFields();
..
$fields->addFieldToTab(
"Root.Content.Main",
new DropdownField(
'ColourSchemes',
'Choose a colour scheme',
$this->dbObject('ColourSchemes')->enumValues())
);
return $fields;
}
This adds the DropdownField and populates it just fine. I then add to the Page_Controller this line:
Requirements::themedCSS($this->owner->ColourSchemes);
This successfully links the page to the style sheet Red.css (or Green.css etc.).
Note: I tried the following code in the Page.ss file to achieve this but it doesn't quite work for me:
<% require themedCSS($ColourSchemes) %>
My problem is with using this method in a SiteConfig file. Trying to add the DropdownField with the above method yields a fatal error 'Fatal error: Call to undefined method SiteConfig::dbObject() in ... mysite\code\siteconfig.php.
The database builds successfully with dev/build/?flush=1 but then when trying to view the DropdownField in the backend the above error is thrown.
My first question is: Am I trying to do this colour scheme idea in a reasonable way? Is there a better and/or easier way to change the colour scheme of a SilverStripe theme?
And secondly: Why is the code not working in the SiteConfig? I understand it's different to page classes, but I haven't wrapped my head around exactly how it's different and what I need to change to get things to work.