diff --git a/forms/CheckboxSetField.php b/forms/CheckboxSetField.php index 7dcad4f8b..cd5f9c944 100755 --- a/forms/CheckboxSetField.php +++ b/forms/CheckboxSetField.php @@ -9,7 +9,6 @@ */ class CheckboxSetField extends OptionsetField { - protected $disabled = false; /** @@ -20,6 +19,7 @@ class CheckboxSetField extends OptionsetField { function Field() { Requirements::css(SAPPHIRE_DIR . '/css/CheckboxSetField.css'); + $source = $this->source; $values = $this->value; // Get values from the join, if available @@ -28,50 +28,50 @@ class CheckboxSetField extends OptionsetField { if(!$values && $record && $record->hasMethod($this->name)) { $funcName = $this->name; $join = $record->$funcName(); - if($join) foreach($join as $joinItem) $values[] = $joinItem->ID; + if($join) { + foreach($join as $joinItem) { + $values[] = $joinItem->ID; + } + } } } - $source = $this->source; - if(!is_array($source) && !is_a($source, 'SQLMap')){ - // Source and values are DataObject sets. + + // Source is not an array + if(!is_array($source) && !is_a($source, 'SQLMap')) { if(is_array($values)) { $items = $values; } else { - if($values&&is_a($values, "DataObjectSet")){ - foreach($values as $object){ - if( is_a( $object, 'DataObject' ) ) + // Source and values are DataObject sets. + if($values && is_a($values, 'DataObjectSet')) { + foreach($values as $object) { + if(is_a($object, 'DataObject')) { $items[] = $object->ID; + } } - }elseif($values&&is_string($values)){ + } elseif($values && is_string($values)) { $items = explode(',', $values); $items = str_replace('{comma}', ',', $items); } } - } else { - - // Sometimes we pass a singluar default value - // thats ! an array && !DataObjectSet - if(is_a($values,'DataObjectSet') || is_array($values)) + // Sometimes we pass a singluar default value thats ! an array && !DataObjectSet + if(is_a($values, 'DataObjectSet') || is_array($values)) { $items = $values; - else{ - $items = explode(',',$values); + } else { + $items = explode(',', $values); $items = str_replace('{comma}', ',', $items); } } - - if(is_array($source)){ - // Commented out to fix "'Specific newsletters' option in 'newsletter subscription form' page type does not work" bug - // See: http://www.silverstripe.com/bugs/flat/1675 - // unset($source[0]); + if(is_array($source)) { unset($source['']); } $odd = 0; $options = ''; + foreach($source as $index => $item) { - if(is_a($item,'DataObject')) { + if(is_a($item, 'DataObject')) { $key = $item->ID; $value = $item->Title; } else { @@ -80,18 +80,16 @@ class CheckboxSetField extends OptionsetField { } $odd = ($odd + 1) % 2; - $extraClass = $odd ? "odd" : "even"; - $extraClass .= " val" . str_replace(' ','',$key); + $extraClass = $odd ? 'odd' : 'even'; + $extraClass .= ' val' . str_replace(' ', '', $key); + $itemID = $this->id() . '_' . ereg_replace('[^a-zA-Z0-9]+', '', $key); + $checked = ''; - $itemID = $this->id() . "_" . ereg_replace('[^a-zA-Z0-9]+','',$key); - - $checked =""; - if(isset($items)){ + if(isset($items)) { in_array($key,$items) ? $checked = " checked=\"checked\"" : $checked = ""; } $this->disabled ? $disabled = " disabled=\"disabled\"" : $disabled = ""; - $options .= "