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>
|
|
|
|
*
|
2012-09-26 23:34:00 +02:00
|
|
|
* 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
|
2010-10-15 05:55:22 +02:00
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* $myField = new ImageField("myName", "Upload image below", null, null, null, "myFolder");
|
|
|
|
* </code>
|
|
|
|
*
|
2012-09-26 23:34:00 +02:00
|
|
|
* 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
|
2010-10-15 05:55:22 +02:00
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* $myField = new ImageField("myName");
|
|
|
|
* $myField->setFolderName('myFolder');
|
|
|
|
* </code>
|
2008-09-28 15:08:56 +02:00
|
|
|
*
|
2012-02-03 00:59:04 +01:00
|
|
|
* @deprecated 3.0 Use UploadField with $myField->allowedExtensions = array('jpg', 'gif', 'png')
|
|
|
|
*
|
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() {
|
2012-07-13 11:37:35 +02:00
|
|
|
Deprecation::notice('3.0', 'Use UploadField', Deprecation::SCOPE_CLASS);
|
2012-02-03 00:59:04 +01:00
|
|
|
|
2012-09-26 23:34:00 +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;
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|