mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Reverted r61492
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@61497 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
8dff62d3cb
commit
413b309d17
@ -10,17 +10,6 @@ class DropdownField extends FormField {
|
||||
|
||||
/**
|
||||
* Creates a new dropdown field.
|
||||
*
|
||||
* $source parameter can be a two dimensional array; creating <optgroup> elements
|
||||
* as needed for the first level of the array, and <option> elements for the second
|
||||
* level.
|
||||
*
|
||||
* If the source array is of a single dimension, then the dropdown just contains
|
||||
* <option> tags as required for each of the items in the source.
|
||||
*
|
||||
* Returns a <select> tag containing all the appropriate <option> and <optgroup>
|
||||
* as required from the source.
|
||||
*
|
||||
* @param $name The field name
|
||||
* @param $title The field title
|
||||
* @param $source An map of the dropdown items
|
||||
@ -46,31 +35,15 @@ class DropdownField extends FormField {
|
||||
function Field() {
|
||||
$classAttr = '';
|
||||
$options = '';
|
||||
|
||||
if($extraClass = trim($this->extraClass())) {
|
||||
$classAttr = "class=\"$extraClass\"";
|
||||
}
|
||||
|
||||
if($this->source) {
|
||||
foreach($this->source as $value => $title) {
|
||||
if(is_array($title)) { // Nested array, create an optgroup
|
||||
$options .= "<optgroup label=\"$value\">";
|
||||
foreach($title as $value2 => $title2) {
|
||||
$selected = $value2 == $this->value ? " selected=\"selected\"" : "";
|
||||
if($selected && $this->value != 0) {
|
||||
$this->isSelected = true;
|
||||
}
|
||||
$options .= "<option$selected value=\"$value2\">$title2</option>";
|
||||
}
|
||||
$options .= "</optgroup>";
|
||||
} else { // Fall back to the standard dropdown field
|
||||
$selected = $value == $this->value ? " selected=\"selected\"" : "";
|
||||
if($selected && $this->value != 0) {
|
||||
$this->isSelected = true;
|
||||
}
|
||||
$options .= "<option$selected value=\"$value\">$title</option>";
|
||||
}
|
||||
if($this->source) foreach($this->source as $value => $title) {
|
||||
$selected = $value == $this->value ? " selected=\"selected\"" : "";
|
||||
if($selected && $this->value != 0) {
|
||||
$this->isSelected = true;
|
||||
}
|
||||
$options .= "<option$selected value=\"$value\">$title</option>";
|
||||
}
|
||||
|
||||
$id = $this->id();
|
||||
|
@ -1,10 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Grouped dropdown, using <optgroup> tags.
|
||||
*
|
||||
* @deprecated - Please use DropdownField instead!
|
||||
*
|
||||
* $source parameter (from DropdownField) must be a two dimensional array.
|
||||
* The first level of the array is used for the <optgroup>, and the second
|
||||
* level are the <options> for each group.
|
||||
@ -18,9 +15,32 @@
|
||||
class GroupedDropdownField extends DropdownField {
|
||||
|
||||
function Field() {
|
||||
user_error('GroupedDropdownField is deprecated. Please use DropdownField instead.', E_USER_NOTICE);
|
||||
// Initialisations
|
||||
$options = '';
|
||||
$classAttr = '';
|
||||
|
||||
return parent::Field();
|
||||
if($extraClass = trim($this->extraClass())) {
|
||||
$classAttr = "class=\"$extraClass\"";
|
||||
}
|
||||
if($this->source) {
|
||||
foreach($this->source as $value => $title) {
|
||||
if(is_array($title)) {
|
||||
$options .= "<optgroup label=\"$value\">";
|
||||
foreach($title as $value2 => $title2) {
|
||||
$selected = $value2 == $this->value ? " selected=\"selected\"" : "";
|
||||
$options .= "<option$selected value=\"$value2\">$title2</option>";
|
||||
}
|
||||
$options .= "</optgroup>";
|
||||
} else { // Fall back to the standard dropdown field
|
||||
$selected = $value == $this->value ? " selected=\"selected\"" : "";
|
||||
$options .= "<option$selected value=\"$value\">$title</option>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$id = $this->id();
|
||||
|
||||
return "<select $classAttr name=\"$this->name\" id=\"$id\">$options</select>";
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user