|
|
@@ -39,8 +39,9 @@ class SelectBoxWidget extends BasicWidget
|
|
|
* When true, the select element will be disabled.
|
|
|
* - `val` - Either a string or an array of options to mark as selected.
|
|
|
* - `empty` - Set to true to add an empty option at the top of the
|
|
|
- * option elements. Set to a string to define the display value of the
|
|
|
- * empty option.
|
|
|
+ * option elements. Set to a string to define the display text of the
|
|
|
+ * empty option. If an array is used the key will set the value of the empty
|
|
|
+ * option while, the value will set the display text.
|
|
|
* - `escape` - Set to false to disable HTML escaping.
|
|
|
*
|
|
|
* ### Options format
|
|
|
@@ -147,8 +148,7 @@ class SelectBoxWidget extends BasicWidget
|
|
|
}
|
|
|
|
|
|
if (!empty($data['empty'])) {
|
|
|
- $value = $data['empty'] === true ? '' : $data['empty'];
|
|
|
- $options = ['' => $value] + (array)$options;
|
|
|
+ $options = $this->_emptyValue($data['empty']) + (array)$options;
|
|
|
}
|
|
|
if (empty($options)) {
|
|
|
return [];
|
|
|
@@ -163,6 +163,26 @@ class SelectBoxWidget extends BasicWidget
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Generate the empty value based on the input.
|
|
|
+ *
|
|
|
+ * @param string|bool|array $value The provided empty value.
|
|
|
+ * @return array The generated option key/value.
|
|
|
+ */
|
|
|
+ protected function _emptyValue($value)
|
|
|
+ {
|
|
|
+ if ($value === true) {
|
|
|
+ return ['' => ''];
|
|
|
+ }
|
|
|
+ if (is_scalar($value)) {
|
|
|
+ return ['' => $value];
|
|
|
+ }
|
|
|
+ if (is_array($value)) {
|
|
|
+ return $value;
|
|
|
+ }
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Render the contents of an optgroup element.
|
|
|
*
|
|
|
* @param string $label The optgroup label text
|