Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » How to do it? New Description Field in Image Edit Section

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 79 Views
  • LG0012
    Avatar
    Community Member
    2 Posts

    How to do it? New Description Field in Image Edit Section Link to this post

    That's what I want:

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: How to do it? New Description Field in Image Edit Section Link to this post

    Taking a look at UploadField (the image upload form) it looks like this form is 'EditForm'. The fields from this form are populated from UploadField::getFileEditFields() which calls getCMSFields() on the File object.

    So using that understanding, modifying the getCMSFields function on the File object is easy.

    1) Create an extension

    **mysite/code/FileExtension.php**

    <?php

    class FileExtension extends DataExtension {

    private static $db = array(
    'ExtraField' => 'Varchar'
    );

    public function updateCMSFields(FieldList $fields) {
    $fields->addFieldToTab('Root.Main', new TextField('ExtraField'));
    }

    2) Apply your extension to File

    In _config.php

    Object::add_extension('File', 'FileExtension');

    (OR use YAML)

    File:
    extensions:
    - FileExtension

    3) Rebuild your database and visit your page with '?flush=1' to clear the cache

    More documentation (http://doc.silverstripe.org/framework/en/reference/dataextension)

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