Skip to content

Commit

Permalink
Merge pull request #17 from redd/master
Browse files Browse the repository at this point in the history
Link generation is done by HtmlHelper::link() added escape and escapeTit...
  • Loading branch information
torifat committed Jul 6, 2014
2 parents fa0a604 + eb345b0 commit a4befe2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Test/Case/View/Helper/MenuBuilderHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ public function testImageMenu() {
'</li',
'<li',
array('a' => array('title' => 'Item 2', 'href' => '/item-2')),
array('img' => array('src' => '/path/my-image.jpg', 'alt' => 'Item 2', 'title' => 'Item 2')),
array('img' => array('src' => '/path/my-image.jpg', 'alt' => 'Item 2')),
array('span' => array('class' => 'label')),
'Item 2',
'</span',
Expand Down
24 changes: 15 additions & 9 deletions View/Helper/MenuBuilderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,24 +279,30 @@ protected function _buildItem(&$item, $pos = -1, &$isActive = false) {
}
}

$target = '';
$urlOptions = array('title' => $item['title']);
if (!empty($item['target'])) {
$target = ' target="' . $item['target'] . '"';
$urlOptions['target'] = $item['target'];
}

$linkClass = '';
if (!empty($item['linkClass'])) {
$linkClass = ' class="' . implode(' ', (array)$item['linkClass']) . '"';
$urlOptions['class'] = $item['linkClass'];
}

if (isset($item['escape'])) {
$urlOptions['escape'] = $item['escape'];
}

if (isset($item['escapeTitle'])) {
$urlOptions['escapeTitle'] = $item['escapeTitle'];
}

$url = '<a title="' . h($item['title']) . '" href="' . $this->Html->url($item['url']) . '"' . $target . $linkClass . '>';
if (!empty($item['image'])) {
$url .= $this->Html->image($item['image'], array('alt' => $item['title'], 'title' => $item['title']));
$url .= '<span class="label">' . h(__($item['title'])) . '</span>';
$urlOptions['escapeTitle'] = false;
$labelTitle = (isset($urlOptions['escape']) && $urlOptions['escape']) ? h($item['title']) : $item['title'];
$url = $this->Html->link($this->Html->image($item['image'], array('alt' => $item['title'])) . '<span class="label">' . $labelTitle . '</span>', $item['url'], $urlOptions);
} else {
$url .= h(__($item['title']));
$url = $this->Html->link($item['title'], $item['url'], $urlOptions);
}
$url .= '</a>';
}

if ($this->settings['indentHtmlOutput']) {
Expand Down

0 comments on commit a4befe2

Please sign in to comment.