Permalink
Browse files

Use label widget in multi-checkbox widget.

  • Loading branch information...
1 parent 7be8648 commit 0fdb8b7c17b7af22f45ee159680bc82be415c8dc @markstory markstory committed Jan 16, 2014
Showing with 33 additions and 12 deletions.
  1. +22 −7 src/View/Input/MultiCheckbox.php
  2. +11 −5 tests/TestCase/View/Input/MultiCheckboxTest.php
View
29 src/View/Input/MultiCheckbox.php
@@ -30,12 +30,29 @@ class MultiCheckbox {
protected $_templates;
/**
+ * Label widget instance.
+ *
+ * @var Cake\View\Input\Label
+ */
+ protected $_label;
+
+/**
* Render multi-checkbox widget.
*
+ * This class uses the following templates:
+ *
+ * - `checkbox` Renders checkbox input controls. Accepts
+ * the `name`, `value` and `attrs` variables.
+ * - `checkboxContainer` Renders the containing div/element for
+ * a checkbox and its label. Accepts the `input`, and `label`
+ * variables.
+ *
* @param Cake\View\StringTemplate $templates
+ * @param Cake\View\Input\Label $label
*/
- public function __construct($templates) {
+ public function __construct($templates, $label) {
$this->_templates = $templates;
+ $this->_label = $label;
}
/**
@@ -130,13 +147,11 @@ protected function _renderInput($checkbox) {
$labelAttrs = [
'for' => $checkbox['id'],
- 'escape' => $checkbox['escape']
- ];
- $label = $this->_templates->format('label', [
- 'text' => $checkbox['escape'] ? h($checkbox['text']) : $checkbox['text'],
+ 'escape' => $checkbox['escape'],
+ 'text' => $checkbox['text'],
'input' => $input,
- 'attrs' => $this->_templates->formatAttributes($labelAttrs)
- ]);
+ ];
+ $label = $this->_label->render($labelAttrs);
return $this->_templates->format('checkboxContainer', [
'label' => $label,
View
16 tests/TestCase/View/Input/MultiCheckboxTest.php
@@ -15,6 +15,7 @@
namespace Cake\Test\TestCase\View\Input;
use Cake\TestSuite\TestCase;
+use Cake\View\Input\Label;
use Cake\View\Input\MultiCheckbox;
use Cake\View\StringTemplate;
@@ -44,7 +45,8 @@ public function setUp() {
* @return void
*/
public function testRenderSimple() {
- $input = new MultiCheckbox($this->templates);
+ $label = new Label($this->templates);
+ $input = new MultiCheckbox($this->templates, $label);
$data = [
'name' => 'Tags[id]',
'options' => [
@@ -86,7 +88,8 @@ public function testRenderSimple() {
* @return void
*/
public function testRenderComplex() {
- $input = new MultiCheckbox($this->templates);
+ $label = new Label($this->templates);
+ $input = new MultiCheckbox($this->templates, $label);
$data = [
'name' => 'Tags[id]',
'options' => [
@@ -130,7 +133,8 @@ public function testRenderComplex() {
* @return void
*/
public function testRenderEscaping() {
- $input = new MultiCheckbox($this->templates);
+ $label = new Label($this->templates);
+ $input = new MultiCheckbox($this->templates, $label);
$data = [
'name' => 'Tags[id]',
'options' => [
@@ -160,7 +164,8 @@ public function testRenderEscaping() {
* @return void
*/
public function testRenderSelected() {
- $input = new MultiCheckbox($this->templates);
+ $label = new Label($this->templates);
+ $input = new MultiCheckbox($this->templates, $label);
$data = [
'name' => 'Tags[id]',
'options' => [
@@ -213,7 +218,8 @@ public function testRenderSelected() {
* @return void
*/
public function testRenderDisabled() {
- $input = new MultiCheckbox($this->templates);
+ $label = new Label($this->templates);
+ $input = new MultiCheckbox($this->templates, $label);
$data = [
'name' => 'Tags[id]',
'options' => [

0 comments on commit 0fdb8b7

Please sign in to comment.