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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

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


Go to End


2 Posts   2740 Views

Avatar
LG0012

Community Member, 2 Posts

27 August 2014 at 9:37pm

Edited: 27/08/2014 9:37pm

That's what I want:

Avatar
Willr

Forum Moderator, 5523 Posts

28 August 2014 at 9:38pm

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)