Skip to content

Commit 4d33d69

Browse files
committed
Use templateParams in BasicWidget.
1 parent 25bcfaa commit 4d33d69

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/View/Widget/BasicWidget.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ public function render(array $data, ContextInterface $context)
6666
'val' => null,
6767
'type' => 'text',
6868
'escape' => true,
69+
'templateParams' => []
6970
];
7071
$data['value'] = $data['val'];
7172
unset($data['val']);
7273

7374
return $this->_templates->format('input', [
7475
'name' => $data['name'],
7576
'type' => $data['type'],
77+
'templateParams' => $data['templateParams'],
7678
'attrs' => $this->_templates->formatAttributes(
7779
$data,
7880
['name', 'type']

tests/TestCase/View/Widget/BasicWidgetTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,34 @@ public function testRenderAttributes()
117117
];
118118
$this->assertHtml($expected, $result);
119119
}
120+
121+
/**
122+
* Test render with template params.
123+
*
124+
* @return void
125+
*/
126+
public function testRenderTemplateParams()
127+
{
128+
$text = new BasicWidget(new StringTemplate([
129+
'input' => '<input type="{{type}}" name="{{name}}"{{attrs}}><span>{{help}}</span>',
130+
]));
131+
$data = [
132+
'name' => 'my_input',
133+
'type' => 'email',
134+
'class' => 'form-control',
135+
'required' => true,
136+
'templateParams' => ['help' => 'SOS']
137+
];
138+
$result = $text->render($data, $this->context);
139+
$expected = [
140+
'input' => [
141+
'type' => 'email',
142+
'name' => 'my_input',
143+
'class' => 'form-control',
144+
'required' => 'required',
145+
],
146+
'<span', 'SOS', '/span'
147+
];
148+
$this->assertHtml($expected, $result);
149+
}
120150
}

0 commit comments

Comments
 (0)