From 912a2ba760c435baede88d45b8313ac2169c0787 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 15 Feb 2014 11:31:12 -0500 Subject: [PATCH] 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. --- src/View/Widget/Radio.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/View/Widget/Radio.php b/src/View/Widget/Radio.php index db76ca6cbd7..bc459448e24 100644 --- a/src/View/Widget/Radio.php +++ b/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'], '-'));} + }