mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #3319 from wilr/movetogetoptions
Moved option list generation to separate method
This commit is contained in:
commit
bdec3158ba
@ -50,6 +50,21 @@ class CheckboxSetField extends OptionsetField {
|
|||||||
public function Field($properties = array()) {
|
public function Field($properties = array()) {
|
||||||
Requirements::css(FRAMEWORK_DIR . '/css/CheckboxSetField.css');
|
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;
|
$source = $this->source;
|
||||||
$values = $this->value;
|
$values = $this->value;
|
||||||
$items = array();
|
$items = array();
|
||||||
@ -104,12 +119,12 @@ class CheckboxSetField extends OptionsetField {
|
|||||||
unset($source['']);
|
unset($source['']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$odd = 0;
|
|
||||||
$options = array();
|
$options = array();
|
||||||
|
|
||||||
if ($source == null) $source = array();
|
if ($source == null) {
|
||||||
|
$source = array();
|
||||||
|
}
|
||||||
|
|
||||||
if($source) {
|
|
||||||
foreach($source as $value => $item) {
|
foreach($source as $value => $item) {
|
||||||
if($item instanceof DataObject) {
|
if($item instanceof DataObject) {
|
||||||
$value = $item->ID;
|
$value = $item->ID;
|
||||||
@ -133,11 +148,12 @@ class CheckboxSetField extends OptionsetField {
|
|||||||
'isDisabled' => $this->disabled || in_array($value, $this->disabledItems)
|
'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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user