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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Adding different DataObjects to same ComplexTableField


Go to End


2 Posts   1876 Views

Avatar
J

Community Member, 3 Posts

26 April 2010 at 3:22am

Edited: 26/04/2010 1:37pm

Hi,

I have a portfolio page that I want to add several different pieces of media to it. Media at this point is either an image or a swf file but later could be more than that.
A media attachment always has a title, the piece of media (file) and a thumbnail.
There are also some differences between the pieces of media. For example for a swf file I also need to store a width and height variable to use later in the html to display it.

I would like to know how to add these two different media attachments, order them (so a page could display say image, swf, image) and have different fields for different media types?

At the moment I have a ComplexTableField in the portfolio page for adding media attachments. So when I go to add a portfolio page to my site I get a complex table field with an "Add Media Attachment" down the bottom. When you add a media attachment it pops up to add the title, thumbnail and file. Unfortunately I can't figure out how to add these extra fields just for attaching swf files. Does anyone have a good solution?

J

Avatar
MarcusDalgren

Community Member, 288 Posts

28 April 2010 at 8:25pm

As far as I know this is not supported. If you want to manage two different data objects you'll have to add two complextablefields/dataobject managers. However when fetching them for display you can mix them.

Let's say your porfolio has something like this

...
public static $has_many = array(
"ImageAttachments" => "ImageAttachment",
"MovieAttachments" => "MovieAttachment"
);
...

Setup two complextablefields or DOM:s in the cms to manage the content and then write a fetch method, for example:
public function getAttachments() {
$images = $this->ImageAttachments();
$movies = $this->MovieAttachments();
$images->merge($movies);
$images->sort("Title");
return $images;
}

This way you'll get a DataObjectSet that contains both the images and the movies and they'll be ordered by title if that's what you want.