Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit 912a2ba760c435baede88d45b8313ac2169c0787 1 parent 6b4c2f4
@markstory markstory authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/View/Widget/Radio.php
View
13 src/View/Widget/Radio.php
@@ -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'])) {
@@ -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'], '-'));}
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.