2017-01-13 20:11:59 +01:00
|
|
|
<?php
|
|
|
|
|
2018-01-19 08:37:55 +01:00
|
|
|
namespace SilverStripe\TagField;
|
2017-01-13 20:11:59 +01:00
|
|
|
|
|
|
|
use SilverStripe\Forms\ReadonlyField;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A readonly extension of TagField useful for non-editable items within the CMS.
|
|
|
|
*
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields
|
|
|
|
*/
|
2018-01-19 08:37:55 +01:00
|
|
|
class ReadonlyTagField extends TagField
|
2017-01-13 20:11:59 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected $readonly = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the readonly field as HTML.
|
|
|
|
*
|
|
|
|
* @param array $properties
|
|
|
|
* @return HTMLText
|
|
|
|
*/
|
|
|
|
public function Field($properties = array())
|
|
|
|
{
|
|
|
|
$options = array();
|
|
|
|
|
|
|
|
foreach ($this->getOptions()->filter('Selected', true) as $option) {
|
|
|
|
$options[] = $option->Title;
|
|
|
|
}
|
|
|
|
|
|
|
|
$field = ReadonlyField::create($this->name . '_Readonly', $this->title);
|
|
|
|
|
|
|
|
$field->setForm($this->form);
|
|
|
|
$field->setValue(implode(', ', $options));
|
|
|
|
return $field->Field();
|
|
|
|
}
|
|
|
|
}
|