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 /

Using an Enum with DataObjectDecorator


Reply


8 Posts   2084 Views

Avatar
mschiefmaker

Community Member, 187 Posts

2 October 2009 at 2:00pm

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

Avatar
mschiefmaker

Community Member, 187 Posts

2 October 2009 at 2:10pm

Edited: 21/10/2009 8:28pm

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

Avatar
mschiefmaker

Community Member, 187 Posts

21 October 2009 at 8:20pm

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

Avatar
ajshort

Community Member, 244 Posts

21 October 2009 at 9:05pm

$this->owner->dbObject...

Avatar
mschiefmaker

Community Member, 187 Posts

22 October 2009 at 7:25am

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

Can you give me a bit more details

Thanks

Catherine

Avatar
ajshort

Community Member, 244 Posts

22 October 2009 at 11:58am

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

Avatar
mi3ll

Community Member, 24 Posts

22 October 2009 at 1:50pm

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.

Avatar
mschiefmaker

Community Member, 187 Posts

22 October 2009 at 8:42pm

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