Skip to content

Commit

Permalink
Extract helper method for generating radio IDs.
Browse files Browse the repository at this point in the history
FormHelper tests rely on id's being unique within a set of radio
elements. A separate method will help with that.
  • Loading branch information
markstory committed Feb 15, 2014
1 parent 6b4c2f4 commit 912a2ba
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/View/Widget/Radio.php
Expand Up @@ -141,7 +141,7 @@ protected function _renderInput($val, $text, $data) {
$radio['name'] = $data['name'];

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

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

/**
* Generate an ID attribute for a radio button.
*
* Ensures that id's for a given set of fields are unique.
*
* @param array $radio The radio properties.
* @return string Generated id.
*/
protected function _id($radio) {
return mb_strtolower(Inflector::slug($radio['name'] . '_' . $radio['value'], '-'));}

}

0 comments on commit 912a2ba

Please sign in to comment.