Skip to content

Commit 912a2ba

Browse files
committed
Extract helper method for generating radio IDs.
FormHelper tests rely on id's being unique within a set of radio elements. A separate method will help with that.
1 parent 6b4c2f4 commit 912a2ba

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/View/Widget/Radio.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected function _renderInput($val, $text, $data) {
141141
$radio['name'] = $data['name'];
142142

143143
if (empty($radio['id'])) {
144-
$radio['id'] = mb_strtolower(Inflector::slug($radio['name'] . '_' . $radio['value'], '-'));
144+
$radio['id'] = $this->_id($radio);
145145
}
146146

147147
if (isset($data['val']) && strval($data['val']) === strval($radio['value'])) {
@@ -197,4 +197,15 @@ protected function _renderLabel($radio, $label, $input, $escape) {
197197
return $this->_label->render($labelAttrs);
198198
}
199199

200+
/**
201+
* Generate an ID attribute for a radio button.
202+
*
203+
* Ensures that id's for a given set of fields are unique.
204+
*
205+
* @param array $radio The radio properties.
206+
* @return string Generated id.
207+
*/
208+
protected function _id($radio) {
209+
return mb_strtolower(Inflector::slug($radio['name'] . '_' . $radio['value'], '-'));}
210+
200211
}

0 commit comments

Comments
 (0)