Jump to:

7938 Posts in 1541 Topics by 945 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ImageDataObjectManager in a DataObjectDecorator

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: 1089 Views
  • briley
    Avatar
    Community Member
    7 Posts

    ImageDataObjectManager in a DataObjectDecorator Link to this post

    I've added an "image gallery" of sorts to a DataObject on my site and I'm trying to use ImageDataObjectManager to manage the images for each DataObject... my code looks like:

    class MyObjectExtraFields extends DataObjectDecorator {
    public function extraStatics() {
    return array(
    'has_many' => array('GalleryImages' => 'MyObjectGalleryImage')
    );
    }

    public function updateCMSFields(FieldSet &$fields) {
    $fields->addFieldToTab('Root.GalleryImages', new ImageDataObjectManager($this->owner, 'GalleryImages', 'MyObjectGalleryImage', 'Image', array(), 'getCMSFields_forPopup'));
    }
    }

    class MyObjectGalleryImage extends DataObject {
    static $db = array('Caption'=>'Varchar(255)', 'Description' => 'HTMLText');
    static $has_one = array('ParentMyObject' => 'MyObject', 'Image' => 'Image');
    public function getCMSFields_forPopup() { ... }
    }

    The problem I'm running into is that whenever I create a new MyObject in the admin the "Gallery Images" tab shows all of the MyObjectGalleryImages that I've added to other MyObjects, and if I delete them it removes them from every MyObject. Am I not linking something together correctly?

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageDataObjectManager in a DataObjectDecorator Link to this post

    You're going to need to use setParentClass("ClassYoureDecorating") on your DOM because it won't be able to automatically assign the parent class from within a decorator.

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