Jump to:

22976 Posts in 11702 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Add extra field to image object

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

Page: 1
Go to End
Author Topic: 277 Views
  • Bereusei
    Avatar
    Community Member
    94 Posts

    Add extra field to image object Link to this post

    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?

  • stallain
    Avatar
    Community Member
    61 Posts

    Re: Add extra field to image object Link to this post

    Hi, instead of the getCMSFields function, try this :

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

  • stallain
    Avatar
    Community Member
    61 Posts

    Re: Add extra field to image object Link to this post

    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');

    277 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.