You are here

function _custom_breadcrumbs_get_breadcrumb in Custom Breadcrumbs 7.2

Same name and namespace in other branches
  1. 6.2 custom_breadcrumbs.module \_custom_breadcrumbs_get_breadcrumb()

Gets the custom breadcrumb.

This function is used to retrieve the breadcrumb trail before actually setting it.

@codingStandardsIgnoreStart

Parameters

object $breadcrumb: The breadcrumb object.

array $objs: An array of object (if available) for building token substituions.

array $locations: Locations array to be able to set active menu trail - passed by reference.

Return value

array array of html crumbs

See also

custom_breadcrumbs_get_breadcrumb()

1 call to _custom_breadcrumbs_get_breadcrumb()
custom_breadcrumbs_set_breadcrumb in ./custom_breadcrumbs.module
Sets the custom breadcrumb.

File

./custom_breadcrumbs.module, line 379
Main file for the Custom breadcrumbs.

Code

function _custom_breadcrumbs_get_breadcrumb($breadcrumb, $objs, &$locations) {
  global $language;

  // @codingStandardsIgnoreEnd
  // Assure locations is an array.
  if (!is_array($locations)) {
    $locations = array();
  }
  elseif (isset($locations['title']) || isset($locations['href'])) {
    $locations = array(
      $locations,
    );
  }
  $trail = custom_breadcrumbs_home_crumb();
  if (!empty($trail)) {

    // @codingStandardsIgnoreLine
    $title = variable_get('custom_breadcrumb_home', t('Home'));
    $link = variable_get('custom_breadcrumb_home_link', '<front>');
    $locations[] = array(
      'title' => variable_get('custom_breadcrumb_home', t('Home')),
      'href' => $link,
      'localized_options' => array(),
    );
  }
  if (variable_get('custom_breadcrumbs_use_php_in_titles', FALSE)) {
    $titles = extract_php($breadcrumb->titles, $objs);

    // Titles and paths arrays can also be provided as elements of an
    // associative array.
    if (isset($titles['titles']) && is_array($titles['titles']) && isset($titles['paths']) && is_array($titles['paths'])) {
      $paths = $titles['paths'];
      $titles = $titles['titles'];
    }
    else {
      $paths = extract_php($breadcrumb->paths, $objs);
    }
  }
  if (!isset($titles) || is_null($titles)) {
    $titles = preg_split("/[\n]+/", $breadcrumb->titles);
  }
  if (!isset($paths) || is_null($paths)) {
    $paths = preg_split("/[\n]+/", $breadcrumb->paths);
  }

  // Token replacement for titles and paths.
  // Prepare objects to be used in token replacement.
  $types = custom_breadcrumbs_token_types($objs);

  // Mourning the loss of token_replace_multiple().
  foreach ($titles as $index => $value) {
    $titles[$index] = token_replace($value, $types, array(
      'clear' => TRUE,
      'language' => $language,
    ));
  }
  foreach ($paths as $index => $value) {
    $paths[$index] = token_replace($value, $types, array(
      'clear' => TRUE,
      'language' => $language,
    ));
  }

  // Optionally append the page title.
  if (variable_get('custom_breadcrumbs_append_page_title', FALSE) && !drupal_is_front_page()) {
    $titles[] = drupal_get_title();
    if (variable_get('custom_breadcrumbs_append_page_title_no_link', FALSE)) {
      $paths[] = '<none>';
    }
    else {
      $paths[] = $_GET['q'];
    }
  }
  $items = _custom_breadcrumbs_get_trail_items($breadcrumb, $titles, $paths);

  // Use the returned items to set the trail.
  foreach ($items as $item) {
    if (!empty($item)) {
      if (isset($item['crumb'])) {
        $trail[] = $item['crumb'];
      }
      if (variable_get('custom_breadcrumbs_force_active_trail', FALSE)) {
        $locations[] = array(
          'title' => $item['title'],
          'href' => drupal_get_normal_path(trim($item['href'])),
        );
      }
    }
  }
  return $trail;
}