Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » How to replicate ImageDataObjectManager behaviour in SS3?

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: 1186 Views
  • JonoM
    Avatar
    Community Member
    103 Posts

    How to replicate ImageDataObjectManager behaviour in SS3? Link to this post

    Does anyone know how to replicate ImageDataObjectManager behaviour in SS3? I'm referring to the ability to have a class such as this:

    class PhotoGalleryImage extends DataObject
    {
       static $db = array (
          'Caption' => 'Text'
       );

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

    Where the focus of the object is on the image relationship, and easily import a bunch of photos at once in to a page like this:

    class PhotoGalleryPage extends Page {
       
       static $has_many = array (
          'PhotoGalleryImages' => 'PhotoGalleryImage'
       );
       
       public function getCMSFields() {
          $fields = parent::getCMSFields();

          //What to put here??

          return $fields;
       }

    }

    Then add captions etc. if necessary afterwards. I tried using GridField but the best I could get to happen is to create one PhotoGalleryImage object at a time - which then has to be saved before adding an image to it. Very time consuming compared to the old way of doing it with ImageDOM and Uploadify!

    Thanks for reading

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: How to replicate ImageDataObjectManager behaviour in SS3? Link to this post

    I just ended up extending the image class with the extra fields and just using the upload field. You upload all the images an hit edit on it to add the extra stuff. Not quite as good as the ImageDOM but its works better than the 1 at a time.

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: How to replicate ImageDataObjectManager behaviour in SS3? Link to this post

    Hi zenmonkey, thanks for the reply - any chance you could provide the code you used for this? Sounds like a good solution.

    Cheers

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: How to replicate ImageDataObjectManager behaviour in SS3? Link to this post

    There's two ways to handle this extension either create a new inidividual class or extend the whole image class. I chose the second way since the option could be used on multiple relations.

    Here is the code

    The image extension

    class CustomImageExtension extends DataExtension {
       
       static $db = array(
          'Feature' => 'Boolean',
          'Caption' => 'Varchar',
          'Cover' => 'Boolean'
       );
       
       static $has_one = array(
          'Listing' => 'Listing',
          'Room' => 'Room',
          'MLSListing' => 'MLSListing'
       );
       
       public function updateCMSFields(FieldList $fields) {
          $fields->addFieldToTab('Root.Main', new TextField('Caption', 'Caption'), 'Name');
          $fields->addFieldToTab('Root.Main', new CheckboxField('Feature', 'Is Feature'), 'Name');
          $fields->addFieldToTab('Root.Main', new CheckboxField('Cover', 'Is Cover'), 'Name');
          $fields->removeByName('OwnerID');
          $fields->removeByName('ParentID');
          $fields->removeByName('BackLinkCount');
       }
       
    }


    Then in your config add
    Object::add_extension('Image', 'CustomImageExtension');

    This adds those fields to all Image Objects, the indidual class option instead of extending DataExtension you'd extend the Image, forget about the line in your config and on your dataobject call the relation to CustomImage instead of Image. Really depends on the functionality you need. I was really just adding a few booleans so I could pull feature image into carousels on parent pages, as I need this on almost every instance of image I just added to the Image Class

    Hope that helps

  • JonoM
    Avatar
    Community Member
    103 Posts
    1186 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.