Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ImageDataObjectManager

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 1591 Views
  • yug
    Avatar
    Community Member
    17 Posts

    ImageDataObjectManager Link to this post

    Hi everyone

    So i am trying to set up the ability to manage Banners. I need the ability for different pages to have different banners and in different orders. It would be nice so that when i add a Banner for a certain page, this banner is also automatically available for another page type. So my idea is to loop through a folder in assets, and link every image to that page.

    I have created a BannerImage class and currently have it working so that when i upload an image, other pages can see this image. However if i rearrange this image on one particular page, it changes in all the other pages

    Can anyone help please?

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageDataObjectManager Link to this post

    Sounds like you want a ManyManyFileDataObjectManager? That will allow you to upload banners from every page, and choose which banners you want, new or existing, to appear on any given page.

  • yug
    Avatar
    Community Member
    17 Posts

    Re: ImageDataObjectManager Link to this post

    Ok so i think i have this set up.....so when i add an image, i can see this image on all pages. But if i change the order of the images on one page, it changes the order on every other page

    Can you please help me in setting this up properly

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageDataObjectManager Link to this post

    Yeah, I think somewhere in this forum you'll see a write up on SortableDataObject::add_sortable_many_many_relation();.. I think it's in a sticky.

  • yug
    Avatar
    Community Member
    17 Posts

    Re: ImageDataObjectManager Link to this post

    I cant seem to find anything and what is a sticky

  • UncleCheese
    Avatar
    4085 Posts
  • yug
    Avatar
    Community Member
    17 Posts

    Re: ImageDataObjectManager Link to this post

    Can you see where i am going wrong

    BannerImage.php
    -------------------------------------------------------------------------------------

    <?php

    class BannerImage extends DataObject {
       
        static $db = array(
              'Title' => 'Text',
           'URL' => 'Text'
        );
       
          static $has_one = array(
           'BannerImage' => 'Image'
        );
       
          static $belongs_many_many = array(
           'Pages' => 'Page'
        );
       
        public function getCMSFields_forPopup()
        {
              return new FieldSet(
                   new TextField('URL'),
                   new FileIFrameField('BannerImage')
                );
        }
    }

    ?>

    Page.php
    -----------------------------------------------------

    <?php
    class Page extends SiteTree {

       public static $db = array(
       );

       public static $has_one = array(
       );
       
       static $many_many = array(
          "BannerImages" => "BannerImage"
       );

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

       $idom = new ManyManyFileDataObjectManager (
        $this,
        'BannerImages',
        'BannerImage',
        'BannerImage',

        array(
        'URL' => 'URL'
        ),
        'getCMSFields_forPopup'
       );

    $idom->setUploadFolder("BannerImages");

    $fields->addFieldToTab("Root.Content.Image", $idom);
       
    return $fields;
    }

    _config.php
    -----------------------------------------------------

    And i added this to the config file

    SortableDataObject::add_sortable_many_many_relation('Page', 'BannerImage');

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageDataObjectManager Link to this post

    I think the second argument is the relation name..

    SortableDataObject::add_sortable_many_many_relation('Page', 'BannerImages');

    1591 Views
Page: 1 2
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.