Skip to content

Commit

Permalink
Remove "default" option from HtmlHelper::link().
Browse files Browse the repository at this point in the history
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 9d64ac6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
11 changes: 1 addition & 10 deletions src/View/Helper/HtmlHelper.php
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 2 additions & 10 deletions tests/TestCase/View/Helper/HtmlHelperTest.php
Expand Up @@ -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'
);
Expand Down

0 comments on commit 9d64ac6

Please sign in to comment.