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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Add extra field to image object


Go to End


3 Posts   2330 Views

Avatar
Bereusei

Community Member, 96 Posts

7 June 2013 at 1:06am

Hey guys,

if I upload an image in silverstripe 3, I can click on "edit" and get information (imageresolution, etc.) over the image and can change the title.
If I modify the class to this:

class PushboxResource extends Image{
	static $db = array (
		'Variable1' => 'Varchar(255)'
    );
	
	public static $many_many = array(
		"myclass" => "myclass"
	);
	
	public function getCMSFields() {
   		$fields = new FieldList(); 
		$fields->push(new TextField('Variable1'));
		return $fields;	
  	}
}

I can add an extra field to the image, but if I do it this way, all the extra information over the image are lost and I only get my textfield.
Is there an nice way to add an extra field to the image parameter without blowing the nice extra information away?

Avatar
stallain

Community Member, 68 Posts

8 June 2013 at 3:22am

Hi, instead of the getCMSFields function, try this :

function getCustomFields() {
     $fields = new FieldList();
     $fields->push(new TextField('Variable1')); 
     return $fields;
     }

Avatar
stallain

Community Member, 68 Posts

9 June 2013 at 5:00am

Sorry, I answered a little too quickly. So that my solution works, I think your PushboxResource class has to extend DataExtension, not 'Image'.
Then, in your _config.php, write :

Object::add_extension('Image', 'PushboxResource');