Jump to:

7913 Posts in 1355 Topics by 930 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Adding DOM Fields in an Extension

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 644 Views
  • dswnz
    Avatar
    Community Member
    9 Posts

    Adding DOM Fields in an Extension Link to this post

    Hi Guys,

    I've created an extension class so I can add Video / Audio to various DataObjects which use the extension.

    It manages to successfully add the Tabs & form fields to the Pages/ DataObjects that I want to extend, the problem I have is that after filling in the form successfully, the Video / Audio object never ends up being added to the Page / DataObject.

    See the Class below

    class ContentMedia extends DataObjectDecorator {

    function extraStatics() {
    return array(
    'has_many' => array(
    'Videos' => 'Video',
    'AudioFiles' => 'AudioFile',
    )
    );
    }

    function updateCMSFields(&$fields) {
    $fields->addFieldToTab("Root.Content.Videos", new FileDataObjectManager(
    parent,
    'Videos',
    'Video',
    'Video',
    array('Title' => 'Title', 'Description' => 'Description'),
    new FieldSet(
    new TextField('Title'),
    new TextareaField('Description')
    )
    ));

    $fields->addFieldToTab("Root.Content.AudioFiles", new FileDataObjectManager(
    'DataObject',
    'Audio Files',
    'AudioFile',
    'AudioFile',
    array('Title' => 'Title', 'Description' => 'Description'),
    new FieldSet(
    new TextField('Title'),
    new TextareaField('Description')
    )
    ));
    }

    }

    …and in my mysite/_config.php I'm adding the extension

    //...
    Object::add_extension('Page', 'ContentMedia');

    And yes, before anyone asks, I've run a dev/build?flush=1

    Cheers.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding DOM Fields in an Extension Link to this post

    Why do you have "parent" as the controller of the DOM? Don't you want $this->owner?

    --------------------
    SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

  • dswnz
    Avatar
    Community Member
    9 Posts

    Re: Adding DOM Fields in an Extension Link to this post

    It was mean to be 'DataObject' not parent, which was still wrong anyway… I've now set them both to $this->owner and they work great!

    Greatly appreciated!
    Thanks UncleCheese!

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