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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

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


Reply


2 Posts   154 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, 5513 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)