Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 53 lines (48 sloc) 1.58 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
<?php
/**
* A field that allows you to attach an image to a record from within a iframe - designed for use in AJAX forms where it
* is not possible to use {@link SimpleImageField}.
*
* <b>Usage</b>
*
* If you want to upload all assets from this field to a given folder you can define the folder in 2 ways. Either in the constructor or as a method on the field
*
* <code>
* $myField = new ImageField("myName", "Upload image below", null, null, null, "myFolder");
* </code>
*
* Will upload images into the assets/myFolder folder. If that folder does not exist it will create it for you. You can also define it as a method
*
* <code>
* $myField = new ImageField("myName");
* $myField->setFolderName('myFolder');
* </code>
*
* @package forms
* @subpackage fields-files
*/
class ImageField extends FileIFrameField {

/**
* @return SimpleImageField_Disabled
*/
public function performReadonlyTransformation() {
return new SimpleImageField_Disabled($this->name, $this->title, $this->value, $this->form);
}

/**
* @return string
*/
public function FileTypeName() {
return _t('ImageField.IMAGE', 'Image');
}

/**
* Adds the filter, so the dropdown displays only images and folders.
*
* @return Form
*/
public function EditFileForm() {
$filter = create_function('$item', 'return (in_array("Folder", ClassInfo::ancestry($item->ClassName)) || in_array("Image", ClassInfo::ancestry($item->ClassName)));');

$form = parent::EditFileForm();
$form->dataFieldByName('ExistingFile')->setFilterFunction($filter);

return $form;
}
}
Something went wrong with that request. Please try again.