Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link generation is done by HtmlHelper::link() added escape and escapeTit... #17

Merged
merged 3 commits into from
Jul 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@redd I was little bit concerned about this one. This means the change will break the current versions. Right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but title is reduntant when you've alt on image and title on the link.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with you that it is redundant. But, before pushing this change I have to add a how to upgrade section. Or, many existing users will end up having a broken site.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that (eventually) don't showing title is a little abuse to have broken sites :) But when image is in the link it should without problems show link's title.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Sorry, I forgot what it is 😄

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