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 {
|
class CheckboxSetField extends OptionsetField {
|
||||||
|
|
||||||
|
|
||||||
protected $disabled = false;
|
protected $disabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,6 +19,7 @@ class CheckboxSetField extends OptionsetField {
|
|||||||
function Field() {
|
function Field() {
|
||||||
Requirements::css(SAPPHIRE_DIR . '/css/CheckboxSetField.css');
|
Requirements::css(SAPPHIRE_DIR . '/css/CheckboxSetField.css');
|
||||||
|
|
||||||
|
$source = $this->source;
|
||||||
$values = $this->value;
|
$values = $this->value;
|
||||||
|
|
||||||
// Get values from the join, if available
|
// Get values from the join, if available
|
||||||
@ -28,50 +28,50 @@ class CheckboxSetField extends OptionsetField {
|
|||||||
if(!$values && $record && $record->hasMethod($this->name)) {
|
if(!$values && $record && $record->hasMethod($this->name)) {
|
||||||
$funcName = $this->name;
|
$funcName = $this->name;
|
||||||
$join = $record->$funcName();
|
$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 is not an array
|
||||||
// Source and values are DataObject sets.
|
if(!is_array($source) && !is_a($source, 'SQLMap')) {
|
||||||
if(is_array($values)) {
|
if(is_array($values)) {
|
||||||
$items = $values;
|
$items = $values;
|
||||||
} else {
|
} else {
|
||||||
if($values&&is_a($values, "DataObjectSet")){
|
// Source and values are DataObject sets.
|
||||||
foreach($values as $object){
|
if($values && is_a($values, 'DataObjectSet')) {
|
||||||
if( is_a( $object, 'DataObject' ) )
|
foreach($values as $object) {
|
||||||
|
if(is_a($object, 'DataObject')) {
|
||||||
$items[] = $object->ID;
|
$items[] = $object->ID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}elseif($values&&is_string($values)){
|
} elseif($values && is_string($values)) {
|
||||||
$items = explode(',', $values);
|
$items = explode(',', $values);
|
||||||
$items = str_replace('{comma}', ',', $items);
|
$items = str_replace('{comma}', ',', $items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// Sometimes we pass a singluar default value thats ! an array && !DataObjectSet
|
||||||
// Sometimes we pass a singluar default value
|
if(is_a($values, 'DataObjectSet') || is_array($values)) {
|
||||||
// thats ! an array && !DataObjectSet
|
|
||||||
if(is_a($values,'DataObjectSet') || is_array($values))
|
|
||||||
$items = $values;
|
$items = $values;
|
||||||
else{
|
} else {
|
||||||
$items = explode(',',$values);
|
$items = explode(',', $values);
|
||||||
$items = str_replace('{comma}', ',', $items);
|
$items = str_replace('{comma}', ',', $items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(is_array($source)) {
|
||||||
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]);
|
|
||||||
unset($source['']);
|
unset($source['']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$odd = 0;
|
$odd = 0;
|
||||||
$options = '';
|
$options = '';
|
||||||
|
|
||||||
foreach($source as $index => $item) {
|
foreach($source as $index => $item) {
|
||||||
if(is_a($item,'DataObject')) {
|
if(is_a($item, 'DataObject')) {
|
||||||
$key = $item->ID;
|
$key = $item->ID;
|
||||||
$value = $item->Title;
|
$value = $item->Title;
|
||||||
} else {
|
} else {
|
||||||
@ -80,18 +80,16 @@ class CheckboxSetField extends OptionsetField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$odd = ($odd + 1) % 2;
|
$odd = ($odd + 1) % 2;
|
||||||
$extraClass = $odd ? "odd" : "even";
|
$extraClass = $odd ? 'odd' : 'even';
|
||||||
$extraClass .= " val" . str_replace(' ','',$key);
|
$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);
|
if(isset($items)) {
|
||||||
|
|
||||||
$checked ="";
|
|
||||||
if(isset($items)){
|
|
||||||
in_array($key,$items) ? $checked = " checked=\"checked\"" : $checked = "";
|
in_array($key,$items) ? $checked = " checked=\"checked\"" : $checked = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->disabled ? $disabled = " disabled=\"disabled\"" : $disabled = "";
|
$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";
|
$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