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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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   2176 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)