Jump to:

5541 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Using an Enum with DataObjectDecorator

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

Page: 1
Go to End
Author Topic: 2058 Views
  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Using an Enum with DataObjectDecorator Link to this post

    Hi
    I have built an extension to DataObjectDecorator. It seems to work fine until I add an an element with an Enum field. I have

    class MemberExtension extends DataObjectDecorator {

    function extraDBFields() {
    return array(
    'db' => array(
              'DirName'=>'Varchar',
             'IncludeInDirectory' => "Enum('t,f','t')", ...

    public function updateCMSFields(FieldSet &$fields) {
       $fields->addFieldToTab('Root.Directory',new TextField("DirName", "Directory Name"));
       $fields->addFieldToTab('Root.Directory',new DropdownField("IncludeInDirectory", "Include In Directory?",singleton('MemberExtension')->dbObject('IncludeInDirectory')->enumValues() )); ...

    not sure if I should be using this singleton or whether I am heading down the wrong track, anythoights?

    Thanks

    MM

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Using an Enum with DataObjectDecorator Link to this post

    I have also tried $fields->addFieldToTab('Root.Directory',new DropdownField("IncludeInDirectory", "Include In Directory?"));
    but this returns an unpopulated LOV.

    If I don't place it at all and it appears on the Main tab, it displays as it should

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Using an Enum with DataObjectDecorator Link to this post

    I am back at this issue again ... I have now upgraded 2.3.3.

    I really need to have it display on a seperate tab as it is is not the only related variable but at the moment the only way I can get it to display with a LOV is not to mention it at all in public function updateCMSFields(FieldSet &$fields)
    then is defaults correctly onto the main tab

    Can anyone help?

    I am getting an error ("There has been an error") when I use

    public function updateCMSFields(FieldSet &$fields) {
       $fields->addFieldToTab('Root.Main',new DropdownField('IncludeInDirectory','IncludeInDirectory', singleton('MemberExtension')->dbObject('IncludeInDirectory')->enumValues()
    ));

    but I am unable to see any details of the error as I would usually put ?isDev=1 at the end of the URL but because the Security details are in a popup this doesn't tell me anything, neither does Firebug. Can anyone tell me how to a get a more useful message?

    Thanks

    Catherine

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Using an Enum with DataObjectDecorator Link to this post

    $this->owner->dbObject...

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Using an Enum with DataObjectDecorator Link to this post

    Hi
    Sorry but I not sure where to put $this->owner->dbObject ...

    Can you give me a bit more details

    Thanks

    Catherine

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Using an Enum with DataObjectDecorator Link to this post

    Instead of singleton('MemberExtension')->dbObject.

  • mi3ll
    Avatar
    Community Member
    24 Posts

    Re: Using an Enum with DataObjectDecorator Link to this post

    Maybe instead of using an enum type for the IncludeInDirectory field you should use a boolean type, then in your form you can create a checkbox field instead to fill this value.

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Using an Enum with DataObjectDecorator Link to this post

    Thank you both.

    Replacing the singleton code worked well.

    The boolean option is a good idea but in this case I actually wanted to use the TRUE/FALSE option

    Cheers

    Catheirne

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