The Menu HTML module allows to add HTML to a menu item's name, which is usually used to display an icon next to the name, like this:
Menu link title <img src="/sites/mysite/files/myicon.png" />
When the "Append page title to breadcrumb" option is checked, the menu name will be determined by drupal_get_title(), which adds a check_plain() and thus destroys the angle brackets around HTML tags and a literal " character. Instead of the icon being displayed within the last piece of the breadcumb, the HTML source is displayed. To restore the image being displayed, menu_breadcrumb.module has to be changed as follows:
Change
if (variable_get('menu_breadcrumb_append_node_title', 0) == 1) {
if (variable_get('menu_breadcrumb_append_node_url', 0) == 1) {
$breadcrumb[] = l(drupal_get_title(), $_GET['q'], array('html' => TRUE));
}
else {
$breadcrumb[] = drupal_get_title();
}
}
(beginning on line 340) to
if (variable_get('menu_breadcrumb_append_node_title', 0) == 1) {
// drupal_get_title() adds check_plain() => angle brackets around HTML tags get lost => restore them
$node_title = drupal_get_title();
$node_title = preg_replace('/</', '<', $node_title);
$node_title = preg_replace('/>/', '>', $node_title);
$node_title = preg_replace('/"/', '"', $node_title);
if (variable_get('menu_breadcrumb_append_node_url', 0) == 1) {
$breadcrumb[] = l($node_title, $_GET['q'], array('html' => TRUE));
}
else {
$breadcrumb[] = $node_title;
}
}
Would you consider to commit this change? Thanks.
Comment | File | Size | Author |
---|---|---|---|
#8 | menu_breadcrumb-special-chars-1149304-4647258.patch | 1.13 KB | GaëlG |
#5 | menu_breadcrumb-Strip_HTML.1149304.D6.patch | 886 bytes | roball |
Comments
Comment #1
xurizaemonFeels like this ought to be done in the site theme, but I appreciate that for some people and sites a tool like Menu HTML may be a better solution so will consider if a patch against 6.x-1.x is supplied.
Comment #2
xurizaemonActually, looking at the code above I think it will need to be better than that.
The preg_replace() in your description won't fully restore HTML, just reverse the HTML encoding of some characters ... that doesn't feel so good.
I don't think I'd commit the code above, no. You're welcome to continue working on this and/or raise some support for the idea if you think I'm wrong!
Comment #3
roball CreditAttribution: roball commentedOK, so let's better get totally rid of HTML that may be within a menu item title, probably specified via the Menu HTML module. Using
menu_get_active_title()
instead ofdrupal_get_title()
keeps the HTML, which can then be stripped out by the following code (replacing my first attempt above):I have successfully tested it. Thanks for considering.
Comment #4
roball CreditAttribution: roball commentedComment #5
roball CreditAttribution: roball commentedAttached is the proper patch against the latest commit of the 6.x-1.x branch.
Comment #6
roball CreditAttribution: roball commentedComment #7
xurizaemonRather than preg_replace(), do you think filter_xss($node_title, array()) or even strip_tags($node_title) might be a better choice?
filter_xss() runs several preg_replace, but makes sense as it re-uses existing Drupal functions rather than trying to roll our own regex tag stripper. Looks like filter_xss() catches a few more cases than the regex in the patch too, eg <title>this <unclosed tag</title>.
Comment #8
GaëlGHere's the patch for D7, with filter_xss suggestion included.
Comment #9
xurizaemonThanks, committed to 6.x-1.x and 7.x-1.x.
Comment #10
roball CreditAttribution: roball commentedThank you grobot for committing. However, you should change the 6.x-1.x-dev release to be built based on the 6.x-1.x branch (instead of master), so the commit will be available in the latest auto-built 6.x-1.x-dev snapshot.
Comment #11
xurizaemonThanks for spotting that roball. Have updated the branch for that release now - I expect the release bot should pick up on this shortly.
Comment #12
roball CreditAttribution: roball commentedCan confirm that Menu Breadcrumb 6.x-1.3+5-dev (2012-Apr-18) fixes the reported problem, especially it now also works fine together with the "Menu HTML" module. Thanks again for committing.
Comment #14
rijkaard CreditAttribution: rijkaard commentedHello, I'm sorry to disagree, but I think this update is misleading because the flag allows the user to enter in the crumbs the title of the page, not the menu item.
If desired, however, this functionality I think you have to keep it separate from the existing settings.
In my case, I was forced to not update the module to version 1.4 for the above reasons.
Comment #15
xurizaemonClosing a lot of ancient (> 4 years) issues. It's fine to re-open if you think there's something of value to be discussed.