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 |
-
Adding DOM Fields in an Extension

22 September 2010 at 10:28am
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.
-
Re: Adding DOM Fields in an Extension

25 September 2010 at 4:03am
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 -
Re: Adding DOM Fields in an Extension

27 September 2010 at 9:44am
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 |

