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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

How can I add stuff to the image class and show in popup?


Go to End


9 Posts   2921 Views

Avatar
joelg

Community Member, 134 Posts

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

24 August 2009 at 9:38am

What do you mean "image class?" For the ImageGallery module?

Avatar
joelg

Community Member, 134 Posts

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?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

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.

Avatar
joelg

Community Member, 134 Posts

25 August 2009 at 1:35am

Edited: 25/08/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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

25 August 2009 at 2:22am

Edited: 25/08/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.

Avatar
joelg

Community Member, 134 Posts

25 August 2009 at 7:55pm

Edited: 25/08/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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

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.

Go to Top