silverstripe-framework/src/Forms/TreeMultiselectField_Readonly.php
Damian Mooyman 68c3279fd9
BUG Ensure readonly tree dropdown is safely encoded
Removed legacy entwine dead code
Added soft-deprecation to label field
2017-10-26 13:04:30 +13:00

41 lines
1.1 KiB
PHP

<?php
namespace SilverStripe\Forms;
class TreeMultiselectField_Readonly extends TreeMultiselectField
{
protected $readonly = true;
public function Field($properties = array())
{
// Build list of titles
$titleField = $this->getTitleField();
$items = $this->getItems();
$titleArray = [];
foreach ($items as $item) {
$titleArray[] = $item->$titleField;
}
$titleList = implode(", ", $titleArray);
// Build list of values
$itemIDs = [];
foreach ($items as $item) {
$itemIDs[] = $item->ID;
}
$itemIDsList = implode(",", $itemIDs);
// Readonly field for display
$field = new ReadonlyField($this->name . '_ReadonlyValue', $this->title);
$field->setValue($titleList);
$field->setForm($this->form);
// Store values to hidden field
$valueField = new HiddenField($this->name);
$valueField->setValue($itemIDsList);
$valueField->setForm($this->form);
return $field->Field() . $valueField->Field();
}
}