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.

Customising the CMS

Populating CMS field with a dropdown of enum values


Reply

3 Posts   3357 Views

Avatar
Andrew Houle

19 December 2008 at 10:02am Community Member, 132 Posts

I'm trying to put together a simple page type that will have a dropdown of days of the week that is pulled from a set of enum values. Here is my code thus far:

<?php

class EveningPage extends Page {
   
   static $db = array(
      'Day' => "Enum('Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday','Monday')",
      'StartDate' => 'Date',
      'EndDate' => 'Date',
      'Comments' => 'Text'
   );
   
   function getCMSFields() {
   $fields = parent::getCMSFields();
   
//This is where I need help
       $fields->addFieldToTab('Root.Content.Main', new DropdownField(
         'Day',
         'Day of the Week:',
         singleton('EveningPage')->dbObject('Day')->enumValues()
      ),
      
      
       $fields->removeFieldFromTab("Root.Content.Main","Content"); //Remove the content field
   
       return $fields;
   }

}

class EveningPage_Controller extends Page_Controller {
      
}

?>

This is not working, and I'm sure I have some things screwy, but I couldn't find much in the way of documentation for this sort of thing. Can anyone help... thanks so much!

Avatar
jamesg

19 December 2008 at 12:17pm (Last edited: 19 December 2008 12:20pm), Community Member, 8 Posts

I think this:

$fields->addFieldToTab('Root.Content.Main', new DropdownField(
'Day',
'Day of the Week:',
singleton('EveningPage')->dbObject('Day')->enumValues()
),


Should be:

$fields->addFieldToTab('Root.Content.Main', new DropdownField(
'Day',
'Day of the Week:',
singleton('EveningPage')->dbObject('Day')->enumValues()
));


That's the only thing I noticed.

Avatar
Andrew Houle

20 December 2008 at 3:34am Community Member, 132 Posts

That did the trick. Thanks for taking the time to look that over!