From 9d64ac6ee4464ffe84eed97f5b6431be20a989d5 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 5 Jul 2014 18:38:07 +0530 Subject: [PATCH] Remove "default" option from HtmlHelper::link(). Adding js code to prevent default behavior of link by itself has little value. --- src/View/Helper/HtmlHelper.php | 11 +---------- tests/TestCase/View/Helper/HtmlHelperTest.php | 12 ++---------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/View/Helper/HtmlHelper.php b/src/View/Helper/HtmlHelper.php index 7fda86449d1..b68216e2e6d 100644 --- a/src/View/Helper/HtmlHelper.php +++ b/src/View/Helper/HtmlHelper.php @@ -296,8 +296,6 @@ public function charset($charset = null) { * - `escapeTitle` Set to false to disable escaping of title. Takes precedence * over value of `escape`) * - `confirm` JavaScript confirmation message. - * - `default` If set to false the default redirection behavior of link will be - * prevented using javascript. * * @param string $title The content to be wrapped by tags. * @param string|array $url Cake-relative URL or array of URL parameters, or @@ -337,15 +335,8 @@ public function link($title, $url = null, array $options = array()) { } if ($confirmMessage) { $options['onclick'] = $this->_confirm($confirmMessage, 'return true;', 'return false;', $options); - } elseif (isset($options['default']) && !$options['default']) { - if (isset($options['onclick'])) { - $options['onclick'] .= ' '; - } else { - $options['onclick'] = ''; - } - $options['onclick'] .= 'event.returnValue = false; return false;'; - unset($options['default']); } + return $this->formatTemplate('link', [ 'url' => $url, 'attrs' => $this->templater()->formatAttributes($options), diff --git a/tests/TestCase/View/Helper/HtmlHelperTest.php b/tests/TestCase/View/Helper/HtmlHelperTest.php index a87ada2d1a0..aa9ba117054 100644 --- a/tests/TestCase/View/Helper/HtmlHelperTest.php +++ b/tests/TestCase/View/Helper/HtmlHelperTest.php @@ -148,17 +148,9 @@ public function testLink() { ); $this->assertTags($result, $expected); - $result = $this->Html->link('Home', '/home', array('default' => false)); + $result = $this->Html->link('Home', '/home', array('onclick' => 'someFunction();')); $expected = array( - 'a' => array('href' => '/home', 'onclick' => 'event.returnValue = false; return false;'), - 'Home', - '/a' - ); - $this->assertTags($result, $expected); - - $result = $this->Html->link('Home', '/home', array('default' => false, 'onclick' => 'someFunction();')); - $expected = array( - 'a' => array('href' => '/home', 'onclick' => 'someFunction(); event.returnValue = false; return false;'), + 'a' => array('href' => '/home', 'onclick' => 'someFunction();'), 'Home', '/a' );