Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ImageDataObjectManager: Is it possible to set title on Image?


Reply


2 Posts   1791 Views

Avatar
jjeziorski

Community Member, 11 Posts

5 July 2009 at 5:22am

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,

Avatar
UncleCheese

Forum Moderator, 4092 Posts

6 July 2009 at 11:57am

Edited: 06/07/2009 11:59am

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.