Initial readonly field modifications

This commit is contained in:
Colin Tucker 2016-02-25 12:32:29 +11:00
parent ddb56be86f
commit 47392c5dde

View File

@ -406,4 +406,49 @@ class TagField extends DropdownField
{
return true;
}
/**
* Converts the field to a readonly variant.
*
* @return TagField_Readonly
*/
public function performReadonlyTransformation()
{
$copy = $this->castedCopy('TagField_Readonly');
return $copy;
}
}
/**
* A readonly extension of TagField useful for non-editable items within the CMS.
*
* @package forms
* @subpackage fields
*/
class TagField_Readonly extends TagField
{
protected $readonly = true;
/**
* Render the field as HTML.
*
* @param array $properties
* @return HTMLText
*/
public function Field($properties = array())
{
$options = array();
foreach ($this->getOptions() as $option) {
$options[] = $option->Title;
}
$field = ReadonlyField::create($this->name.'_Readonly', $this->title);
$field->setForm($this->form);
$field->setValue(implode(', ', $options));
return $field->Field();
}
}