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('/&lt;/', '<', $node_title);
    $node_title = preg_replace('/&gt;/', '>', $node_title);
    $node_title = preg_replace('/&quot;/', '"', $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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xurizaemon’s picture

Status: Active » Needs work

Feels 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.

xurizaemon’s picture

Actually, 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!

roball’s picture

Status: Needs review » Needs work

OK, 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 of drupal_get_title() keeps the HTML, which can then be stripped out by the following code (replacing my first attempt above):

  if (variable_get('menu_breadcrumb_append_node_title', 0) == 1) {
    $node_title = menu_get_active_title();
    $node_title = preg_replace('/<[^>]*>.*$/', '', $node_title);
    if (variable_get('menu_breadcrumb_append_node_url', 0) == 1) {
      $breadcrumb[] = $is_front ? l(t('Home'), '<front>') : l($node_title, $_GET['q'], array('html' => TRUE,));
    }
    else {
      $breadcrumb[] = $is_front ? t('Home') : $node_title;
    }
  }

I have successfully tested it. Thanks for considering.

roball’s picture

Title: Support Menu HTML module » Strip HTML inserted by the "Menu HTML" module out of breadcrumb
Status: Needs work » Needs review
roball’s picture

Status: Needs work » Needs review
FileSize
886 bytes

Attached is the proper patch against the latest commit of the 6.x-1.x branch.

roball’s picture

Version: 6.x-1.3 » 6.x-1.x-dev
xurizaemon’s picture

Rather 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>.

GaëlG’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
FileSize
1.13 KB

Here's the patch for D7, with filter_xss suggestion included.

xurizaemon’s picture

Status: Needs review » Fixed

Thanks, committed to 6.x-1.x and 7.x-1.x.

roball’s picture

Title: Strip HTML inserted by the "Menu HTML" module out of breadcrumb » Handle menu entries with embedded HTML (resolves conflict with "Menu HTML" module)

Thank 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.

xurizaemon’s picture

Thanks for spotting that roball. Have updated the branch for that release now - I expect the release bot should pick up on this shortly.

roball’s picture

Can 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rijkaard’s picture

Version: 7.x-1.x-dev » 7.x-1.4
Status: Closed (fixed) » Active

Hello, 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.

xurizaemon’s picture

Status: Active » Closed (outdated)

Closing a lot of ancient (> 4 years) issues. It's fine to re-open if you think there's something of value to be discussed.