mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Code formatting cleanup on CheckboxSetField->Field()
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@66628 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ca2c814cd9
commit
087cba096e
@ -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)) {
|
||||
$items = $values;
|
||||
} else {
|
||||
$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))
|
||||
$items = $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 .= "<li class=\"$extraClass\"><input id=\"$itemID\" name=\"$this->name[$key]\" type=\"checkbox\" value=\"$key\"$checked $disabled class=\"checkbox\" /> <label for=\"$itemID\">$value</label></li>\n";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user