Jump to:

7937 Posts in 1537 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ImageDataObjectManager: Is it possible to set title on Image?

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: 1736 Views
  • jjeziorski
    Avatar
    Community Member
    11 Posts

    ImageDataObjectManager: Is it possible to set title on Image? Link to this post

    Hey,
    I like this module very much. Great work!
    I have an ImageDataObjectManager running smoothly with simple DataObject (just image, parentPage and title). However, I wonder is it possible to work with image object "Title" rather than extra property?

    I imagine two approaches:
    1. use an object extending Image class

    class PageImage extends Image
    {
       static $has_one = array (
          'ParentPage' => 'Page'
       );
       
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Title'),
             new FileIFrameField('GD')
          );
       }
    }


    However this won't satisfy ImageDataObjectManager constructor parameters and has awkward Image field

    2. use Dataobject and write "Title" to Image object

    class PageImage extends DataObject
    {
       static $has_one = array (
          'Photo' => 'Image',
          'ParentPage' => 'Page'
       );
       
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Photo.Title'),
             new FileIFrameField('Photo')
          );
       }
    }


    This seems coherent, however it doesn't work ;)

    Am i doing something wrong? Any ideas?

    Thanks,

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageDataObjectManager: Is it possible to set title on Image? Link to this post

    It sounds like what you want is to extend the ImageGalleryItem class.

    class MyImage extends ImageGalleryItem
    {
    static $db = array (
    'MyField' => 'Text'
    );
    public function getCMSFields_forPopup();
    {
    $f = parent::getCMSFields_forPopup();
    $f->push(new TextField('Title'));
    return $f;
    }
    }

    Then you need to create a custom ImageGalleryPage class, too.

    class MyImageGalleryPage extends ImageGalleryPage
    {
    public $itemClass = "MyImage";
    }

    I wouldn't use Title as a custom field, though, because it's already on the Image object associated with ImageGalleryItem.

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