7913 Posts in 1355 Topics by 930 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 834 Views |
-
How to replicate ImageDataObjectManager behaviour in SS3?

13 September 2012 at 8:47am Last edited: 13 September 2012 8:48am
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
-
Re: How to replicate ImageDataObjectManager behaviour in SS3?

7 December 2012 at 1:36am
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.
-
Re: How to replicate ImageDataObjectManager behaviour in SS3?

11 December 2012 at 8:37am
Hi zenmonkey, thanks for the reply - any chance you could provide the code you used for this? Sounds like a good solution.
Cheers
-
Re: How to replicate ImageDataObjectManager behaviour in SS3?

12 December 2012 at 5:16am
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
-
Re: How to replicate ImageDataObjectManager behaviour in SS3?

12 December 2012 at 5:57am
Thanks man!
| 834 Views | ||
|
Page:
1
|
Go to Top |


