mirror of
https://github.com/silverstripe/silverstripe-tagfield
synced 2024-10-22 11:05:32 +02:00
Initial readonly field modifications
This commit is contained in:
parent
ddb56be86f
commit
47392c5dde
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user