Skip to content
Permalink
Browse files

Reduce the number of templates used.

By adding {{attrs}} I can re-add support for arbitrary properties on
option elements. As well as the [name => foo, value => bar] format for
option elements.
  • Loading branch information...
markstory committed Jan 8, 2014
1 parent a2d7f8d commit de15f6835b46957d9c980ca79514d3356e43c6e7
Showing with 9 additions and 12 deletions.
  1. +8 −8 Cake/View/Input/SelectBox.php
  2. +1 −4 Test/TestCase/View/Input/SelectBoxTest.php
@@ -137,19 +137,19 @@ protected function _renderOptions($options, $disabled, $selected, $escape) {
'content' => implode('', $groupOptions)
]);
} else {
$template = 'option';
$isSelected = $this->_isSelected($key, $selected);
$isDisabled = $this->_isDisabled($key, $disabled);
if ($isSelected) {
$template .= 'Selected';
$optAttrs = [];
if ($this->_isSelected($key, $selected)) {
$optAttrs['selected'] = true;
}
if ($isDisabled) {
$template .= 'Disabled';
if ($this->_isDisabled($key, $disabled)) {
$optAttrs['disabled'] = true;
}
$optAttrs['escape'] = $escape;
$out[] = $this->_templates->format($template, [
$out[] = $this->_templates->format('option', [
'name' => $escape ? h($key) : $key,
'value' => $escape ? h($val) : $val,
'attrs' => $this->_templates->formatAttributes($optAttrs),
]);
}
}
@@ -27,10 +27,7 @@ public function setUp() {
parent::setUp();
$templates = [
'select' => '<select name="{{name}}"{{attrs}}>{{content}}</select>',
'option' => '<option value="{{name}}">{{value}}</option>',
'optionSelected' => '<option value="{{name}}" selected="selected">{{value}}</option>',
'optionDisabled' => '<option value="{{name}}" disabled="disabled">{{value}}</option>',
'optionSelectedDisabled' => '<option value="{{name}}" selected="selected" disabled="disabled">{{value}}</option>',
'option' => '<option value="{{name}}"{{attrs}}>{{value}}</option>',
'optgroup' => '<optgroup label="{{label}}">{{content}}</optgroup>',
];
$this->templates = new StringTemplate();

0 comments on commit de15f68

Please sign in to comment.
You can’t perform that action at this time.