7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » How can I add stuff to the image class and show in popup?
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 1275 Views |
-
How can I add stuff to the image class and show in popup?

24 August 2009 at 8:56am
Hi
I would like to know if anyone has tried adding fields to the image class?
I've tried to use the DataObjectDecorator, and it works fine, but I'm not sure how to show/edit the $fields in the popup window.
At the moment I have the default 4 fields (Name, Title, Filename and Content) and I just want to add my new fields to these.
Can anyone help?
Thanks many times.
Joel
-
Re: How can I add stuff to the image class and show in popup?

24 August 2009 at 9:38am
What do you mean "image class?" For the ImageGallery module?
-
Re: How can I add stuff to the image class and show in popup?

24 August 2009 at 11:18pm
Well, that's the question... I'm pretty confused about this part, maybe this picture will explain it better:
So basically I just want to add things to this popup window in the Files & Images part of the CMS... Does it make sense?
-
Re: How can I add stuff to the image class and show in popup?

25 August 2009 at 1:08am
Yeah, this is a minor bug right now. The AssetAdmin with DataObjectManager will not respect decorated File objects. It's a simple fix, and I had someone submit a patch, but when I went to check on it, the file had been removed. I hope to sort it out soon.
But yes, you're right. You should be able to decorate the Image class and use updateCMSFields().
For now, in dataobject_manager/_config.php, just set allow_asset_override(false);
I'll repost to this thread when the fix is in.
-
Re: How can I add stuff to the image class and show in popup?

25 August 2009 at 1:35am Last edited: 25 August 2009 1:47am
Hi UncleCheese
Thanks for a quick answer. You helped me in the right direction.
I found a solution: First I extended the File class in mysite/_config.php, like this:
Object::add_extension('File', 'GalleriPulsArtImage');
Then I created the extended class:
class GalleriPulsArtImage extends Extension
{public function extraStatics() {
return array(
'db' => array(
'Kategori' => "Enum('Link, Billede')"
)
);
}
}And last I edited AssetManager.php with an extra line i the $fields variable in the constructur:
new DropdownField('Kategori','Kategori', singleton('File')->dbObject('Kategori')->enumValues()),
It seems to work for now. Of course if there is a smarter solution please let me know.
Thanks again.
Joel
-
Re: How can I add stuff to the image class and show in popup?

25 August 2009 at 2:22am Last edited: 25 August 2009 2:23am
You shouldn't hack the core code because when you update to a new version your changes will break. I've actually just made that update so if you run an update it should use your updateCMSFields() function now.
-
Re: How can I add stuff to the image class and show in popup?

25 August 2009 at 7:55pm Last edited: 25 August 2009 7:58pm
Hi UncleCheese
Thanks for a quick update. I installed it and here is some feedback/questions.
I noticed that allow_asset_override is set to false per default in _config.php - however this just turns the dataObjectManager completely off in the Files & Images. Why? I just turned it back on with 'true'.
The updateCMSFields function now works, however doing a SimpleTreeDropdownField returns a simple textfield with the ID in it... Here is my code for the extended class:
class ExtendedImage extends Extension
{public function extraStatics() {
return array(
'db' => array(
'Kategori' => "Enum('Billede, Link')",
'SiteLinkID' => 'Int'
),
'has_one' => array(
'SiteLink' => 'SiteTree',
'BilledeThumb' => 'Image',
),
);
}
public function updateCMSFields(FieldSet &$fields) {
$fields->push(new DropdownField('Kategori','Kategori', singleton('File')->dbObject('Kategori')->enumValues()));
$fields->push(new SimpleTreeDropdownField('SiteLinkID','Vælge en side (hvis kategorien er et link)'));
$fields->push(new FileIFrameField('BilledeThumb'));
return $fields;
}
}The last thing. In mysite/_config.php I've written:
Object::add_extension('File', 'ExtendedImage');
Now this works, the problem is that the extended class also shows up when I click on folders. See this photo which explains:
I tried to change it to:
Object::add_extension('Image', 'ExtendedImage');
But with no luck, silverstripe just returns an error...
Ok, I know, many question, but hope you can help. Thanks again.
Joel
-
Re: How can I add stuff to the image class and show in popup?

26 August 2009 at 1:42am
You have conflicting fields in your model.
'db' => array(
'Kategori' => "Enum('Billede, Link')",
'SiteLinkID' => 'Int'
),
'has_one' => array(
'SiteLink' => 'SiteTree',
'BilledeThumb' => 'Image',
),You should remove SiteLinkID from your db array and leave it as a has_one. Right now, you have two fields fighting over the column "SiteLinkID"
Run an update and see if it helps you with the other issues.
| 1275 Views | ||
| Go to Top | Next > |

