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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Same Images for multiple Image subclasses


Go to End


5 Posts   1537 Views

Avatar
schmig

Community Member, 3 Posts

22 October 2010 at 2:17pm

Hi there
I'm new to silverstripe - and I like it very much.
Currently I'm working on a portfolio website, that uses lots of images in different contexts.
On one page, there is a navigation-image (standard "Image" class) an imageDOM to handle multiple portfolio images (ClassName "PortfolioBild") and another imageDOM for additional pictures (ClassName "ReferenzBild").
Everything works fine and the look and feel with DOM and Uploadify is very nice.
Unfortunately, I ran into problem and would appreciate some help:
I would like to use the same uploaded picture for multiple purposes. But DOM/Silverstripe seems to filter by ClassName. Eg I upload an image as "PortfolioBild" and then I would like to import the same images as "ReferenzBild", the system will ignore my request. If I manually change the ClassName in the "file" table to "ReferenzBild", DOM will allow me to import the image, but it's no longer visible as "PortfolioBild".

This is how my Portfolio Class looks like (the ReferenzBild is almost the same):

class PortfolioBild extends Image {
static $db = array(
'Legende' => 'Text'
);

public static $has_one = array(
"Attachment" => "File",
"ContentImages" => "ContentImages"
);
}

The ContentImages looks like this:

class ContentImages extends Page {
static $db = array(
'Legende' => 'Text'
);

static $has_many = array(
'PortfolioImages' => 'PortfolioBild',
'ReferenzImages' => 'ReferenzBild'
);

static $has_one = array(
'Menubild' => 'Image'
);

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Main', new TextField('Legende'), 'Content');

$fields->addFieldToTab("Root.Content.Navigation", new ImageField('Menubild'));

$images = new ImageDataObjectManager(
$this,
'PortfolioImages',
'PortfolioBild',
'Attachment',
array(),
'getCMSFields_forPopup'
);
$fields->addFieldToTab("Root.Content.Portfolio", $images);

$ref_images = new ImageDataObjectManager(
$this,
'ReferenzImages',
'ReferenzBild',
'Attachment',
array(),
'getCMSFields_forPopup'
);
$fields->addFieldToTab("Root.Content.Referenz", $ref_images);

return $fields;
}
}

How can I give my client three different areas to select images - and enabling him to use the same image on the same page in multiple areas?
Is there a way to tell my PortfolioBild and ReferenzBild classes to store as ClassName "Image"?
Any hint or help is very much appreciated.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

22 October 2010 at 5:01pm

Wow, there's some weird stuff going on, here. I'm not sure you're using ImageDataObjectManager properly, or that it's what you really want for this setup.

FileDataObjectManager and ImageDataObjectManager are used to manage file-containing DataObjects. That is, any dataobject that contains its own file relationship.

It looks to me like you're trying to manage a File or Image relationship directly on the page, not through another dataobject relationship. But that's not really clear because your PortfolioBild object is a subclass of Image.. but yet it has its own relationship to a File, too. So I'm not really sure what's going on there.

If all you want is to manage multiple images on a page, you probably just want a MultipleImageUploadField, or if you want the DOM interface, an ImageAssetManager.

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

Avatar
schmig

Community Member, 3 Posts

22 October 2010 at 5:31pm

Thanks for the prompt reply.
Yes, all I really need is two sets of multiple images. But there is a need for some additional fields for each image - so the standard Image class won't do it.
I will try find out more about MultipleImageUploadField and the ImageAssetManager.
Btw. the file attachment is from an example I found in this forum.
But now I know, I'm on the wrong track. Thanks UncleCheese for your help.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

22 October 2010 at 5:43pm

If you have additional fields in addition to the image, then you do want an ImageDOM.. but your DataObject shouldn't subclass Image.

class YourImage extends DataObject {

static $db = array (
'Title' => 'Text',
'Caption' => 'Text'
);

static $has_one = array (
'GalleryPage' => 'GalleryPage',
'Image' => 'Image'
);

public function getCMSFields() {
...
}
}

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

Avatar
schmig

Community Member, 3 Posts

22 October 2010 at 7:30pm

That's very kind of you.
I can't try it right now, but this sounds very good.
Will this kind of subclassing work for many_many relationship as well? So that the GalleryPage (in your example) has many_many YourImage and in the YourImage I would only need the corresponding "belongs" array?