You are here

public function MenutrailbypathBreadcrumb::setBreadcrumb in Menu Trail By Path 7.3

Sets the breadcrumb by path

See also

menu_get_active_breadcrumb()

File

src/MenutrailbypathBreadcrumb.inc, line 23

Class

MenutrailbypathBreadcrumb

Code

public function setBreadcrumb() {
  $breadcrumb = array();
  $this
    ->setActiveTrail();

  // No breadcrumb for the front page.
  if (drupal_is_front_page()) {
    return;
  }
  $active_trail = menu_get_active_trail();
  $item = end($active_trail);
  if (!empty($item['href'])) {

    // Allow modules to alter the breadcrumb, if possible, as that is much
    // faster than rebuilding an entirely new active trail.
    drupal_alter('menu_breadcrumb', $active_trail, $item);

    // Don't show a link to the current page in the breadcrumb trail.
    $end = end($active_trail);
    if ($item['href'] == $end['href']) {
      $current_page_link = array_pop($active_trail);
    }

    // Remove the tab root (parent) if the current path links to its parent.
    // Normally, the tab root link is included in the breadcrumb, as soon as we
    // are on a local task or any other child link. However, if we are on a
    // default local task (e.g., node/%/view), then we do not want the tab root
    // link (e.g., node/%) to appear, as it would be identical to the current
    // page. Since this behavior also needs to work recursively (i.e., on
    // default local tasks of default local tasks), and since the last non-task
    // link in the trail is used as page title (see menu_get_active_title()),
    // this condition cannot be cleanly integrated into menu_get_active_trail().
    // menu_get_active_trail() already skips all links that link to their parent
    // (commonly MENU_DEFAULT_LOCAL_TASK). In order to also hide the parent link
    // itself, we always remove the last link in the trail, if the current
    // router item links to its parent.
    if (($item['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT) {
      array_pop($active_trail);
    }
    foreach ($active_trail as $parent) {
      $breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']);
    }
    if (!empty($current_page_link)) {
      $drupal_page_title = drupal_get_title();
      if (!empty($drupal_page_title) && $current_page_link['href'] == current_path()) {
        $current_page_link['title'] = $drupal_page_title;
      }
      if (MenutrailbypathConfig::get('breadcrumb_display_current_page') == 'yes_link') {
        $link_options = $current_page_link['localized_options'];
        $link_options['attributes']['class'][] = 'breadcrumb__item--current-page';
        $link_options['attributes']['class'][] = 'active';
        $breadcrumb[] = l($current_page_link['title'], $current_page_link['href'], $link_options);
      }
      elseif (MenutrailbypathConfig::get('breadcrumb_display_current_page') == 'yes_span') {
        $breadcrumb[] = '<span class="breadcrumb__item--current-page">' . $current_page_link['title'] . '</span>';
      }
    }
  }
  drupal_set_breadcrumb($breadcrumb);
}