Skip to content
Permalink
Browse files

Remove "default" option from HtmlHelper::link().

Adding js code to prevent default behavior of link by itself has little value.
  • Loading branch information...
ADmad committed Jul 5, 2014
1 parent 156265f commit 9d64ac6ee4464ffe84eed97f5b6431be20a989d5
Showing with 3 additions and 20 deletions.
  1. +1 −10 src/View/Helper/HtmlHelper.php
  2. +2 −10 tests/TestCase/View/Helper/HtmlHelperTest.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 <a> 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),
@@ -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'
);

0 comments on commit 9d64ac6

Please sign in to comment.
You can’t perform that action at this time.