Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DataExtensions and Inherited getCMSFields

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

Page: 1
Go to End
Author Topic: 562 Views
  • SamTheJarvis
    Avatar
    Community Member
    24 Posts

    DataExtensions and Inherited getCMSFields Link to this post

    Got a question here that's stumped me.

    My LocationDataExtension adds a some fields, namely address, longitude and latitude.

    It applies to a number of DataObjects, however the additional CMS Fields don't show if I'm not using the inherited CMS Fields, via parent::getCMSFields.

    Since a number of the objects it applies to are quite gigantic, I've used $fields = new FieldList(new TabSet('Root')); to simplify the form building (meaning I don't have to remove all the fields manually), but it seems fields added by DataExtensions won't be included this way.

    My Questions:

    Is there a way to get all fields that should be added to a DataObject via extensions and add them separately - avoiding the use of parent::getCMSFields()?

    Is there perhaps a way to turn form scaffolding off on a per instance basis - allowing me to use parent::getCMSFields which would return no scaffolded fields? Or a way to remove the default scaffolded fields?

    Thanks,
    Sam

  • SamTheJarvis
    Avatar
    Community Member
    24 Posts

    Re: DataExtensions and Inherited getCMSFields Link to this post

    The answer to this (thanks to kinglozzer on the IRC) is:

    $fields = new FieldList(new TabSet('Root'));

    //add your fields as normal, for example
    $fields->addFieldsToTab('Root.Main', array(
       new TextField('Title'),
       $exterior_image = new UploadField('ExteriorImage', 'Exterior image')
    ));
    $exterior_image ->setFolderName('external_images');

    //magic bit

    $this->extend('updateCMSFields', $fields);
    return $fields;

    So, this allows you to not use the inherited/scaffolded fields provided by parent::getCMSFields(), but also include fields added by any applicable DataExtensions.

    Super!

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