2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2009-05-18 00:06:59 +02:00
|
|
|
* 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}.
|
2010-10-15 05:55:22 +02:00
|
|
|
*
|
|
|
|
* <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>
|
2008-09-28 15:08:56 +02:00
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-files
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2009-05-18 00:06:59 +02:00
|
|
|
class ImageField extends FileIFrameField {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return SimpleImageField_Disabled
|
|
|
|
*/
|
|
|
|
public function performReadonlyTransformation() {
|
|
|
|
return new SimpleImageField_Disabled($this->name, $this->title, $this->value, $this->form);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2009-05-18 00:06:59 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2009-05-18 00:06:59 +02:00
|
|
|
* @return string
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2009-05-18 00:06:59 +02:00
|
|
|
public function FileTypeName() {
|
|
|
|
return _t('ImageField.IMAGE', 'Image');
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2009-05-18 00:06:59 +02:00
|
|
|
|
2009-07-31 02:46:07 +02:00
|
|
|
/**
|
|
|
|
* Adds the filter, so the dropdown displays only images and folders.
|
|
|
|
*
|
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
public function EditFileForm() {
|
2010-10-15 05:02:17 +02:00
|
|
|
$filter = create_function('$item', 'return (in_array("Folder", ClassInfo::ancestry($item->ClassName)) || in_array("Image", ClassInfo::ancestry($item->ClassName)));');
|
2009-07-31 02:46:07 +02:00
|
|
|
|
|
|
|
$form = parent::EditFileForm();
|
2012-01-02 15:03:35 +01:00
|
|
|
$form->Fields()->dataFieldByName('ExistingFile')->setFilterFunction($filter);
|
2009-07-31 02:46:07 +02:00
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
2009-05-18 00:06:59 +02:00
|
|
|
}
|