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   2071 Views

Avatar
mschiefmaker

2 October 2009 at 2:00pm Community Member, 187 Posts

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

2 October 2009 at 2:10pm (Last edited: 21 October 2009 8:28pm), Community Member, 187 Posts

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

21 October 2009 at 8:20pm Community Member, 187 Posts

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

21 October 2009 at 9:05pm Community Member, 244 Posts

$this->owner->dbObject...

Avatar
mschiefmaker

22 October 2009 at 7:25am Community Member, 187 Posts

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

Can you give me a bit more details

Thanks

Catherine

Avatar
ajshort

22 October 2009 at 11:58am Community Member, 244 Posts

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

Avatar
mi3ll

22 October 2009 at 1:50pm Community Member, 24 Posts

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

22 October 2009 at 8:42pm Community Member, 187 Posts

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