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.

Customising the CMS /

Customize Upload Manager for Images


Reply


3 Posts   530 Views

Avatar
s_a_m_y

Community Member, 25 Posts

6 July 2013 at 1:17am

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

Avatar
s_a_m_y

Community Member, 25 Posts

6 July 2013 at 1:54am

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

Avatar
karantan

Community Member, 1 Post

23 August 2013 at 9:46pm

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?