1 <?php
2 3 4 5 6 7
8 class OptionsetField extends DropdownField {
9
10 11 12
13 protected $disabledItems = array();
14
15 16 17 18 19 20 21 22
23 function __construct($name, $title = "", $source = array(), $value = "", $form = null) {
24 parent::__construct($name, $title, $source, $value, $form);
25 }
26
27 28 29 30 31 32
33 function Field() {
34 $options = array();
35 $odd = 0;
36 $source = $this->getSource();
37 foreach($source as $value => $title) {
38 $value_lat = Convert::rus2lat($value);
39 $itemID = $this->id() . "_" . ereg_replace('[^a-zA-Z0-9]+','', $value_lat);
40
41 $odd = ($odd + 1) % 2;
42 $extraClass = $odd ? "odd" : "even";
43 $extraClass .= " val" . preg_replace('/[^a-zA-Z0-9\-\_]/','_', $value_lat);
44 $checked = ($value == $this->value) ? 1 : 0;
45 $disabled = ($this->disabled || in_array($value, $this->disabledItems)) ? 1 : 0;
46
47 $options[] = new ArrayData(array(
48 'ID' => $itemID,
49 'Class' => $extraClass,
50 'Name' => $this->name,
51 'Value' => $value,
52 'Title' => $title,
53 'isChecked' => $value == $this->value,
54 'isDisabled' => $disabled,
55 ));
56 }
57 $attributes = array(
58 'class' => "optionset {$this->extraClass()}",
59 'id' => $this->id(),
60 );
61 return $this->createTag('input', $attributes, new DataObjectSet($options));
62 }
63
64 function performReadonlyTransformation() {
65
66 $items = $this->getSource();
67 $field = new LookupField($this->name,$this->title ? $this->title : "" ,$items,$this->value);
68 $field->setForm($this->form);
69 $field->setReadonly(true);
70 return $field;
71 }
72
73 74 75 76 77 78
79 function setDisabledItems($items) {
80 $this->disabledItems = $items;
81 }
82
83 84 85
86 function getDisabledItems() {
87 return $this->disabledItems;
88 }
89
90 function () {
91 return new DataObjectSet();
92 }
93 }
94 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-