diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index b8af0222b36..7678ed609a2 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -94,7 +94,7 @@ class FormHelper extends Helper { 'inputContainer' => '
{{content}}
', 'inputContainerError' => '
{{content}}{{error}}
', 'label' => '{{text}}', - 'nestingLabel' => '{{input}}{{text}}', + 'nestingLabel' => '{{hidden}}{{input}}{{text}}', 'legend' => '{{text}}', 'option' => '', 'optgroup' => '{{content}}', @@ -769,6 +769,9 @@ public function label($fieldName, $text = null, array $options = []) { 'text' => $text, ]; if (isset($options['input'])) { + if (is_array($options['input'])) { + $attrs = $options['input'] + $attrs; + } return $this->widget('nestingLabel', $attrs); } return $this->widget('label', $attrs); @@ -1298,17 +1301,22 @@ public function checkbox($fieldName, array $options = []) { $output = ''; if ($options['hiddenField']) { - $hiddenOptions = array( + $hiddenOptions = [ 'name' => $options['name'], - 'value' => ($options['hiddenField'] !== true ? $options['hiddenField'] : '0'), + 'value' => ($options['hiddenField'] !== true && $options['hiddenField'] !== '_split' ? $options['hiddenField'] : '0'), 'form' => isset($options['form']) ? $options['form'] : null, 'secure' => false - ); + ]; if (isset($options['disabled']) && $options['disabled']) { $hiddenOptions['disabled'] = 'disabled'; } $output = $this->hidden($fieldName, $hiddenOptions); } + + if ($options['hiddenField'] == '_split') { + unset($options['hiddenField'], $options['type']); + return ['hidden' => $output, 'input' => $this->widget('checkbox', $options)]; + } unset($options['hiddenField'], $options['type']); return $output . $this->widget('checkbox', $options); } diff --git a/src/View/Widget/LabelWidget.php b/src/View/Widget/LabelWidget.php index 7c88e4dfb3f..f92c655a821 100644 --- a/src/View/Widget/LabelWidget.php +++ b/src/View/Widget/LabelWidget.php @@ -72,13 +72,15 @@ public function render(array $data, ContextInterface $context) { $data += [ 'text' => '', 'input' => '', + 'hidden' => '', 'escape' => true, ]; return $this->_templates->format($this->_labelTemplate, [ 'text' => $data['escape'] ? h($data['text']) : $data['text'], 'input' => $data['input'], - 'attrs' => $this->_templates->formatAttributes($data, ['text', 'input']), + 'hidden' => $data['hidden'], + 'attrs' => $this->_templates->formatAttributes($data, ['text', 'input', 'hidden']), ]); }