Rewrote class attribute assignment

This commit is contained in:
xhs345 2016-05-18 23:04:23 -07:00
parent 615be3ad14
commit dcd7563707

View file

@ -932,11 +932,14 @@ class FormHelper extends AppHelper {
if (isset($options['legend'])) { if (isset($options['legend'])) {
$legend = $options['legend']; $legend = $options['legend'];
unset($options['legend']);
} }
if (isset($options['fieldset'])) { if (isset($options['fieldset'])) {
$fieldset = $options['fieldset']; $fieldsetAttrs = ['class' => $options['fieldset']];
unset($options['fieldset']);
} }
if (empty($fields)) { if (empty($fields)) {
$fields = $modelFields; $fields = $modelFields;
} }
@ -971,17 +974,13 @@ class FormHelper extends AppHelper {
$out .= $this->input($name, $options); $out .= $this->input($name, $options);
} }
if (is_string($fieldset)) {
$fieldsetClass = sprintf(' class="%s"', $fieldset);
} else {
$fieldsetClass = '';
}
if ($fieldset) { if ($fieldset) {
if ($legend) { if ($legend) {
$out = $this->Html->useTag('legend', $legend) . $out; $out = $this->Html->useTag('legend', $legend) . $out;
} }
$out = $this->Html->useTag('fieldset', $fieldsetClass, $out); $out = $this->Html->useTag('fieldset', $fieldsetAttrs, $out);
} }
return $out; return $out;
} }
@ -1545,9 +1544,9 @@ class FormHelper extends AppHelper {
$legend = __(Inflector::humanize($this->field())); $legend = __(Inflector::humanize($this->field()));
} }
$fieldset = ''; $fieldsetAttrs = '';
if (isset($attributes['fieldset'])) { if (isset($attributes['fieldset'])) {
$fieldset = $attributes['fieldset']; $fieldsetAttrs = ['class' => $attributes['fieldset']];
unset($attributes['fieldset']); unset($attributes['fieldset']);
} }
@ -1644,13 +1643,10 @@ class FormHelper extends AppHelper {
if (is_array($between)) { if (is_array($between)) {
$between = ''; $between = '';
} }
if ($legend) { if ($legend) {
if (is_string($fieldset)) { $out = $this->Html->useTag('legend', $legend) . $between . $out;
$fieldsetClass = sprintf(' class="%s"', $fieldset); $out = $this->Html->useTag('fieldset', $fieldsetAttrs, $out);
} else {
$fieldsetClass = '';
}
$out = $this->Html->useTag('fieldset', $fieldsetClass, $this->Html->useTag('legend', $legend) . $between . $out);
} }
return $out; return $out;
} }