Jump to:

5554 Posts in 1742 Topics by 1227 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Customize Upload Manager for Images

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

Page: 1
Go to End
Author Topic: 519 Views
  • s_a_m_y
    Avatar
    Community Member
    25 Posts

    Customize Upload Manager for Images Link to this post

    Hi everyone,

    for a project I have set up a nice project catalog with the help of the DataObjectsAsPage-Module. Everything works beautifully with SS3. Each project can have multiple categories and multiple images attached. This is also all working great. Images and categories can be defined in separate tabs of the project admin area.
    However my customer now wants to add a photographer to each image and I am struggling somewhat on how to add an extra field to the image uploadField. I figured I need a class that extends Image or DataExtension and adds a table to the database. I defined this extended class in my project page as $many_many relation. I can add images but the extra field doesn't show.

    I've tried something like, trying to adapt the doc on UploadFileds:

    class ExtendedImage extends DataExtension {
       static $db = array(
          'Photographer' => 'Varchar',
          );
             
       static $has_one = array(
    'Image' => 'Image'
    );   

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

    class Project extends DataObjectAsPage
    {
    [...]
    static $many_many = array(
    'ExtendedImages' => 'ExtendedImage',
    'Categories' => 'Category'
    );
    public function getCMSFields() {
    $fields = parent::getCMSFields();
    [...]
    $fields->addFieldToTab("Root.Images", $uploadField->setFileEditFields('getCustomFields'););

    return $fields;

    But I get an internal server error. This must be fairly simple. I'm just not seeing it. All I really need is an additional Textfield in the UploadField of the image Class. I'd be very grateful for any hint on this.

    Sam

  • s_a_m_y
    Avatar
    Community Member
    25 Posts

    Re: Customize Upload Manager for Images Link to this post

    OK. I am getting there slowly. Here is the current code:

    class ExtendedImage extends Image {
       static $db = array(
          'Photographer' => 'Varchar',
          );
             
       static $has_one = array(
    'Image' => 'Image'
    );   

    public function getCustomFields() {
    $fields = new FieldList();
    $fields->push(new TextField('Title', 'Titel'));
    $fields->push(new TextField('Filename', 'Dateiname'));
    $fields->push(new TextField('Alt', 'Alt'));
    $fields->push(new TextField('Photographer', 'Fotograf'));
    $fields->push(new DropdownField('Owner', 'Eigentümer'));
    $fields->push(new DropdownField('Folder', 'Ordner'));
    return $fields;
    }
    }


    class Project extends DataObjectAsPage
    {
    [...]
    static $many_many = array(
    'ExtendedImages' => 'ExtendedImage',
    'Categories' => 'Category'
    );
    public function getCMSFields() {
    $fields = parent::getCMSFields();
    [...]
    $uploadField = new UploadField('Photo','Bilder');
    $uploadField->setConfig('fileEditFields', 'getCustomFields');
    $fields->addFieldToTab("Root.Bilder", $uploadField);

    return $fields;

    I now can access the tab an all field I defined in getCustomFields are being offered. Title will also grasp the title from the image Class as well as the filename. However owner and folder are empty dropdownFields now. I am not sure the field name is correct here or if I have to reset the relation. But as title and filename are rendered correctly I assume it's somthing else I'm not getting. Still any help appreciated.

    Samy

  • karantan
    Avatar
    Community Member
    1 Post

    Re: Customize Upload Manager for Images Link to this post

    the last code was correct. but you have forgot to /dev/build your site. (90% that this is the problem)

    i have another question. the method that samy described overwrites the default view which contains image and data of that image (type, dimensions, path, ...).

    how do you only extend the default fields?

    519 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.