Source of file GroupedListboxField.php
Size: 2,424 Bytes - Last Modified: 2021-12-23T10:05:09+00:00
/var/www/docs.ssmods.com/process/src/src/GroupedListboxField.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 | <?php class GroupedListboxField extends ListboxField { public function Field($properties = array()) { if($this->multiple) $this->name .= '[]'; $options = array(); $groupedOptions = array(); if(is_array($this->value)){ foreach($this->getSource() as $value => $title) { if(is_array($title)) { $options = array(); foreach($title as $value2 => $title2) { $options[] = new ArrayData(array( 'Title' => $title2, 'Value' => $value2, 'Selected' => (in_array($value2, $this->value) || in_array($value2, $this->defaultItems)), 'Disabled' => $this->disabled || in_array($value2, $this->disabledItems), )); } $groupedOptions[] = new ArrayData(array( 'Title' => $value, 'Options' => ArrayList::create($options) )); } else { $options[] = new ArrayData(array( 'Title' => $title, 'Value' => $value, 'Selected' => (in_array($value, $this->value) || in_array($value, $this->defaultItems)), 'Disabled' => $this->disabled || in_array($value, $this->disabledItems), )); } } } else { // Listbox was based a singlular value, so treat it like a dropdown. foreach($this->getSource() as $value => $title) { if(is_array($title)) { $options = array(); foreach($title as $value2 => $title2) { $options[] = new ArrayData(array( 'Title' => $title2, 'Value' => $value2, 'Selected' => ($value2 == $this->value || in_array($value2, $this->defaultItems)), 'Disabled' => $this->disabled || in_array($value2, $this->disabledItems), )); } $groupedOptions[] = new ArrayData(array( 'Title' => $value, 'Options' => ArrayList::create($options) )); } else { $options[] = new ArrayData(array( 'Title' => $title, 'Value' => $value, 'Selected' => ($value == $this->value || in_array($value, $this->defaultItems)), 'Disabled' => $this->disabled || in_array($value, $this->disabledItems), )); } } } if(count($groupedOptions)) $options = $groupedOptions; if($this->emptyString) { $options = array(new ArrayData(array( 'Value' => '', 'Title' => $this->emptyString, ))) + $options; } $properties = array_merge($properties, array( 'Options' => new ArrayList($options) )); return $this->customise($properties)->renderWith($this->getTemplates()); } } |