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