From c60bad30d534c3f948d2c88c734bc94856532851 Mon Sep 17 00:00:00 2001 From: Nik Chankov Date: Wed, 3 Jul 2013 00:43:51 +0100 Subject: [PATCH 1/2] Add class to radio option Adding class to the radio option, so now it can accept "inline" and position radio buttons next to each other. --- View/Helper/BoostCakeHtmlHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/View/Helper/BoostCakeHtmlHelper.php b/View/Helper/BoostCakeHtmlHelper.php index da45083..5eb3273 100644 --- a/View/Helper/BoostCakeHtmlHelper.php +++ b/View/Helper/BoostCakeHtmlHelper.php @@ -19,11 +19,11 @@ public function useTag($tag) { if ($tag === 'radio') { $regex = '/()/'; if (preg_match($regex, $html, $match)) { - $html = $match[1] . ' class="radio"' . $match[2] . preg_replace($regex, ' ', $html); + $html = $match[1] . ' class="radio'.(isset($args[3]['class']) ? ' '.$args[3]['class'] : '').'"' . $match[2] . preg_replace($regex, ' ', $html); } } return $html; } -} \ No newline at end of file +} From afcd01971461f60b3f941f30c47e1963b8120929 Mon Sep 17 00:00:00 2001 From: Yasuo Harada Date: Thu, 4 Jul 2013 11:17:32 +0900 Subject: [PATCH 2/2] fixed how to get class, and add test case --- Test/Case/View/Helper/BoostCakeHtmlHelperTest.php | 10 ++++++++++ View/Helper/BoostCakeHtmlHelper.php | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Test/Case/View/Helper/BoostCakeHtmlHelperTest.php b/Test/Case/View/Helper/BoostCakeHtmlHelperTest.php index 9d7f7f5..556e51a 100644 --- a/Test/Case/View/Helper/BoostCakeHtmlHelperTest.php +++ b/Test/Case/View/Helper/BoostCakeHtmlHelperTest.php @@ -24,6 +24,16 @@ public function testUseTag() { ' label', '/label' )); + + $result = $this->Html->useTag( + 'radio', 'one', 'two', array('class' => 'radio-inline', 'three' => 'four'), '' + ); + $this->assertTags($result, array( + 'label' => array('class' => 'radio-inline', 'for' => 'one'), + 'input' => array('type' => 'radio', 'name' => 'one', 'id' => 'two', 'three' => 'four'), + ' label', + '/label' + )); } } diff --git a/View/Helper/BoostCakeHtmlHelper.php b/View/Helper/BoostCakeHtmlHelper.php index 5eb3273..f9cc6fd 100644 --- a/View/Helper/BoostCakeHtmlHelper.php +++ b/View/Helper/BoostCakeHtmlHelper.php @@ -14,12 +14,18 @@ class BoostCakeHtmlHelper extends HtmlHelper { */ public function useTag($tag) { $args = func_get_args(); + + if ($tag === 'radio') { + $class = (isset($args[3]['class'])) ? $args[3]['class'] : 'radio'; + unset($args[3]['class']); + } + $html = call_user_func_array(array('parent', 'useTag'), $args); if ($tag === 'radio') { $regex = '/()/'; if (preg_match($regex, $html, $match)) { - $html = $match[1] . ' class="radio'.(isset($args[3]['class']) ? ' '.$args[3]['class'] : '').'"' . $match[2] . preg_replace($regex, ' ', $html); + $html = $match[1] . ' class="' . $class . '"' . $match[2] . preg_replace($regex, ' ', $html); } }