Panels breadcrumbs's results can't be altered.
So this patch (see #5 and #7) allow the use of hook_menu_breadcrumb_alter().

Comments

bennetteson’s picture

Status: Active » Needs review
bennetteson’s picture

StatusFileSize
new3.26 KB

Add real alter capacity.
Please review.

bennetteson’s picture

StatusFileSize
new3.5 KB

The good one now.
Please review.

devuo’s picture

Thanks for the contribution, I'll review it during the weekend and commit it if there's no problem with it.

nod_’s picture

Why the new hook? can't it be done with the default menu_breadcrumb ?

Something like the following would work. There is a little bit of copy/paste from menu_get_active_breadcrumb(). On the plus side, it doesn't break themes who alter breadcrumb and you can add classes and everything you want in the alter hook.

And actually It really bugged me that whatever is in $breadcrumbs is HTML and not an array. No way to properly theme the thing.

replace around line 131 until the end of the function

<?php
  $default = array(
    'title' => '',
    'href' => '',
    'localized_options' => array(),
  );
  // Sets the First Crumb to Home.
  // TODO Should probably add an admin configuration page to change this.
  $breadcrumbs = array(array('title' => t('Home'), 'href' => '<front>') + $default);
  // Iterate through all titles and add them to the breadcrumb
  foreach ($titles as $key => $title) {
    $title = trim($title);
    $path = trim($paths[$key]);
    $breadcrumbs[] = array('title' => t($title), 'path' => $path) + $default;
  }

  drupal_alter('menu_breadcrumb', $breadcrumbs, end($breadcrumbs));
  foreach ($breadcrumbs as $parent) {
    $breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']);
  }
  drupal_set_breadcrumb($breadcrumb);
?>

And you don't need the config to configure the <front> link anymore.

bennetteson’s picture

Will test your code today.

bennetteson’s picture

Issue summary: View changes

Better description.

bennetteson’s picture

StatusFileSize
new1.86 KB

I'm partialy agree with you. But your script do not permit to use <none> path to have a no-link item in breadcrumb.

So I upgrate your script :

  $default = array(
    'title' => '',
    'href' => '',
    'localized_options' => array(),
  );
  // Sets the First Crumb to Home.
  // TODO Should probably add an admin configuration page to change this.
  $breadcrumbs_info = array(array('title' => t('Home'), 'href' => '<front>') + $default);
  // Iterate through all titles and add them to the breadcrumb
  foreach ($titles as $key => $title) {
    $title = trim($title);
    $path = trim($paths[$key]);
    $breadcrumbs_info[] = array('title' => t($title), 'href' => $path) + $default;
  }

  drupal_alter('menu_breadcrumb', $breadcrumbs_info, end($breadcrumbs_info));
  $breadcrumbs = array();
  foreach ($breadcrumbs_info as $parent) {
    if (isset($parent['href']) && $parent['href'] == '<none>') {
      $parent['localized_options'] += array('attributes' => array(), 'html' => false);
      $breadcrumbs[] = '<span ' . drupal_attributes($parent['localized_options']['attributes']) . '>' . ($parent['localized_options']['html'] ? $parent['title'] : check_plain($parent['title'])) . '</span>';
    }
    else {
      $breadcrumbs[] = l($parent['title'], $parent['href'], $parent['localized_options']);
    }
  }
  drupal_set_breadcrumb($breadcrumbs);
bennetteson’s picture

StatusFileSize
new1.86 KB

no need isset($parent['href']).

Please review.

nod_’s picture

Oh ok, sure it was quick and dirty for a proof of concept. I expected to be magically accepted by l().

I'm not sure why you'd want a breadcrumb element without a link but hey, i'm not everybody. for example Zen takes care of that at the theme level with a theme setting and a bit of preprocess magic.

I see that the custom_breadcrumbs dev version will handle panels too http://drupalcode.org/project/custom_breadcrumbs.git/tree/refs/heads/7.x...

nod_’s picture

Status: Needs review » Reviewed & tested by the community

all good :)

bennetteson’s picture

Great !!! :)

nod_’s picture

Status: Reviewed & tested by the community » Needs review

Actually it should be the maintainer reviewing this.

bennetteson’s picture

Will be, see #4

devuo’s picture

Status: Needs review » Patch (to be ported)

Apparently it's all good, so I'll be writing later today an panels_breadcrumbs.api.php to expose this hook to IDEs and for clear documentation. I'll probably release 7.x-1.2 with these changes today or tomorrow. Thanks for the valuable contribution :)

bennetteson’s picture

@devuo.
You don't have to. Finally this patch do not declare a new hook, Only use hook_menu_breadcrumb_alter() witch is a build-in drupal hook.

See #5 and http://api.drupal.org/api/drupal/modules--system--system.api.php/functio...

devuo’s picture

Ah- ! It's all good then, will commit it later today ;)

devuo’s picture

Status: Patch (to be ported) » Fixed

7.x-1.2 has been released.

devuo’s picture

Status: Fixed » Closed (fixed)
devuo’s picture

Issue summary: View changes

Now use hook_menu_breadcrumb_alter().