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.

General Questions /

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

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

Add extra field to image object


Reply


3 Posts   410 Views

Avatar
Bereusei

Community Member, 94 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, 61 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, 61 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');