Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Populating CMS field with a dropdown of enum values

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

Page: 1
Go to End
Author Topic: 2898 Views
  • Andrew Houle
    Avatar
    Community Member
    132 Posts

    Populating CMS field with a dropdown of enum values Link to this post

    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!

  • jamesg
    Avatar
    Community Member
    8 Posts

    Re: Populating CMS field with a dropdown of enum values Link to this post

    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.

  • Andrew Houle
    Avatar
    Community Member
    132 Posts

    Re: Populating CMS field with a dropdown of enum values Link to this post

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

    2898 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.