diff --git a/code/TagField.php b/code/TagField.php index 5b60250..3be84e9 100644 --- a/code/TagField.php +++ b/code/TagField.php @@ -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(); + } +} \ No newline at end of file