From 48efa1d5369d7fa9e5d8b069f159bfce0ba3dbb2 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 18 Dec 2016 12:53:14 +0100 Subject: [PATCH] CheckboxList: removed compatibility workaround for label vs item label (BC break) --- src/Forms/Controls/CheckboxList.php | 8 ++++---- tests/Forms/Controls.CheckboxList.render.phpt | 13 ------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/Forms/Controls/CheckboxList.php b/src/Forms/Controls/CheckboxList.php index bc208a10c..8f95e4048 100644 --- a/src/Forms/Controls/CheckboxList.php +++ b/src/Forms/Controls/CheckboxList.php @@ -41,7 +41,7 @@ public function __construct($label = NULL, array $items = NULL) $this->control->type = 'checkbox'; $this->container = Html::el(); $this->separator = Html::el('br'); - // $this->itemLabel = Html::el('label'); back compatiblity + $this->itemLabel = Html::el('label'); $this->setOption('type', 'checkbox'); } @@ -65,7 +65,7 @@ public function getControl(): Html 'required' => NULL, 'data-nette-rules:' => [key($items) => $input->attrs['data-nette-rules']], ]), - $this->itemLabel ? $this->itemLabel->attrs : $this->label->attrs, + $this->itemLabel->attrs, $this->separator ) ); @@ -97,7 +97,7 @@ public function getControlPart($key = NULL): Html public function getLabelPart($key = NULL): Html { - $itemLabel = $this->itemLabel ? clone $this->itemLabel : clone $this->label; + $itemLabel = clone $this->itemLabel; return func_num_args() ? $itemLabel->setText($this->translate($this->items[$key]))->for($this->getHtmlId() . '-' . $key) : $this->getLabel(); @@ -127,7 +127,7 @@ public function getContainerPrototype(): Html */ public function getItemLabelPrototype(): Html { - return $this->itemLabel ?: $this->itemLabel = Html::el('label'); + return $this->itemLabel; } } diff --git a/tests/Forms/Controls.CheckboxList.render.phpt b/tests/Forms/Controls.CheckboxList.render.phpt index ccd885c09..1cb8690fd 100644 --- a/tests/Forms/Controls.CheckboxList.render.phpt +++ b/tests/Forms/Controls.CheckboxList.render.phpt @@ -192,16 +192,3 @@ test(function () { // item label prototype Assert::same('', (string) $input->getLabelPart('a')); Assert::same('', (string) $input->getControl()); }); - - -test(function () { // item label prototype (back compatiblity) - $form = new Form; - $input = $form->addCheckboxList('list', NULL, [ - 'a' => 'b', - ]); - $input->getLabelPrototype()->class('foo'); - - Assert::same('', (string) $input->getLabel()); - Assert::same('', (string) $input->getLabelPart('a')); - Assert::same('', (string) $input->getControl()); -});