Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Same Images for multiple Image subclasses

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 968 Views
  • schmig
    Avatar
    Community Member
    3 Posts

    Same Images for multiple Image subclasses Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Same Images for multiple Image subclasses Link to this post

    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

  • schmig
    Avatar
    Community Member
    3 Posts

    Re: Same Images for multiple Image subclasses Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Same Images for multiple Image subclasses Link to this post

    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

  • schmig
    Avatar
    Community Member
    3 Posts

    Re: Same Images for multiple Image subclasses Link to this post

    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?

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