2016-08-19 10:51:35 +12:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms;
|
|
|
|
|
|
|
|
class TreeMultiselectField_Readonly extends TreeMultiselectField
|
|
|
|
{
|
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
protected $readonly = true;
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2020-04-20 18:58:09 +01:00
|
|
|
public function Field($properties = [])
|
2016-11-29 12:31:16 +13:00
|
|
|
{
|
2017-10-26 13:04:30 +13:00
|
|
|
// Build list of titles
|
|
|
|
$titleField = $this->getTitleField();
|
|
|
|
$items = $this->getItems();
|
|
|
|
$titleArray = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$titleArray[] = $item->$titleField;
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
2017-10-26 13:04:30 +13:00
|
|
|
$titleList = implode(", ", $titleArray);
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2017-10-26 13:04:30 +13:00
|
|
|
// Build list of values
|
|
|
|
$itemIDs = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$itemIDs[] = $item->ID;
|
|
|
|
}
|
|
|
|
$itemIDsList = implode(",", $itemIDs);
|
|
|
|
|
|
|
|
// Readonly field for display
|
2016-11-29 12:31:16 +13:00
|
|
|
$field = new ReadonlyField($this->name . '_ReadonlyValue', $this->title);
|
|
|
|
$field->setValue($titleList);
|
|
|
|
$field->setForm($this->form);
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2017-10-26 13:04:30 +13:00
|
|
|
// Store values to hidden field
|
2016-11-29 12:31:16 +13:00
|
|
|
$valueField = new HiddenField($this->name);
|
|
|
|
$valueField->setValue($itemIDsList);
|
|
|
|
$valueField->setForm($this->form);
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
return $field->Field() . $valueField->Field();
|
|
|
|
}
|
2016-08-19 10:51:35 +12:00
|
|
|
}
|