Moved checkboxset option list generation to separate method

This allows subclasses and extensions time to modify the list of options and their configuration without having to override the entire Field method.

A more flexible way to implement silverstripe#3311
This commit is contained in:
Will Rossiter 2014-07-22 23:48:45 +12:00
parent 59e7f777a2
commit 5a14b7227c

View File

@ -50,6 +50,21 @@ class CheckboxSetField extends OptionsetField {
public function Field($properties = array()) {
Requirements::css(FRAMEWORK_DIR . '/css/CheckboxSetField.css');
$properties = array_merge($properties, array(
'Options' => $this->getOptions()
));
return $this->customise($properties)->renderWith(
$this->getTemplates()
);
}
/**
* @return ArrayList
*/
public function getOptions() {
$odd = 0;
$source = $this->source;
$values = $this->value;
$items = array();
@ -104,12 +119,12 @@ class CheckboxSetField extends OptionsetField {
unset($source['']);
}
$odd = 0;
$options = array();
if ($source == null) $source = array();
if ($source == null) {
$source = array();
}
if($source) {
foreach($source as $value => $item) {
if($item instanceof DataObject) {
$value = $item->ID;
@ -133,11 +148,12 @@ class CheckboxSetField extends OptionsetField {
'isDisabled' => $this->disabled || in_array($value, $this->disabledItems)
));
}
}
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
$options = new ArrayList($options);
return $this->customise($properties)->renderWith($this->getTemplates());
$this->extend('updateGetOptions', $options);
return $options;
}
/**