You are here

function _path_breadcrumbs_build_breadcrumbs in Path Breadcrumbs 7.2

Same name and namespace in other branches
  1. 7.3 path_breadcrumbs.module \_path_breadcrumbs_build_breadcrumbs()
  2. 7 path_breadcrumbs.module \_path_breadcrumbs_build_breadcrumbs()

Build breadcrumbs navigation from loaded path breadcrumb variant.

Parameters

$path_breadcrumb: Object with path breadcrumb variant loaded from database.

$contexts: Ctools contexts from current URL.

Return value

array Array with breadcrumbs navigation.

1 call to _path_breadcrumbs_build_breadcrumbs()
path_breadcrumbs_load_variant in ./path_breadcrumbs.module
Load path breadcrumb variant for page url.

File

./path_breadcrumbs.module, line 94
Provide core functions for path breadcrumbs modue.

Code

function _path_breadcrumbs_build_breadcrumbs($path_breadcrumb, $contexts = array()) {
  $breadcrumb = array();

  // Add hook_path_breadcrumbs_view() for other developers.
  module_invoke_all('path_breadcrumbs_view', $path_breadcrumb, $contexts);

  // Prepend HOME link to breadcrumbs navigation.
  if ($path_breadcrumb->home == TRUE) {
    $home = variable_get('path_breadcrumbs_home_link_title', 'Home');
    $breadcrumb[] = l(t($home), '<front>');
  }

  // Convert breadcrumb titles and paths to string.
  $titles = implode("\n", $path_breadcrumb->titles);
  $paths = implode("\n", $path_breadcrumb->paths);

  // Replace module placeholders.
  $replace = array();
  $search = array();

  // Replace placeholders by its value from url.
  if (!empty($path_breadcrumb->arguments)) {
    foreach ($path_breadcrumb->arguments as $keyword => $argument) {
      $search[] = '!' . $keyword;
      $replace[] = arg($argument['position']);
    }
  }

  // Replace placeholder for current page title.
  $search[] = '!page_title';
  $replace[] = drupal_get_title();

  // Replace module placeholders.
  $titles = str_replace($search, $replace, $titles);
  $paths = str_replace($search, $replace, $paths);

  // Convert arguments from url to contexts.
  if (!empty($contexts)) {

    // Replace placeholders by current context values.
    $titles = ctools_context_keyword_substitute($titles, array(), $contexts);
    $paths = ctools_context_keyword_substitute($paths, array(), $contexts);
  }

  // Explode titles and paths into array.
  $path_breadcrumb->titles_prepared = explode("\n", $titles);
  $path_breadcrumb->paths_prepared = explode("\n", $paths);
  foreach ($path_breadcrumb->titles_prepared as $key => $title) {

    // Remove breadcrumb from navigation if it is empty.
    if (empty($title)) {
      continue;
    }

    // Translate breadcrumb title if needed.
    if ($path_breadcrumb->translatable == TRUE) {
      $title = t($title);
    }

    // Decode title if required.
    $decode_html_entities = variable_get('path_breadcrumbs_decode_entities', TRUE);
    if ($decode_html_entities) {
      $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
    }

    // Set a breadcrumb as a link or as a plain text.
    if (isset($path_breadcrumb->paths_prepared[$key]) && $path_breadcrumb->paths_prepared[$key] != '<none>') {
      $breadcrumb[] = l($title, $path_breadcrumb->paths_prepared[$key]);
    }
    elseif (isset($path_breadcrumb->paths_prepared[$key]) && $path_breadcrumb->paths_prepared[$key] == '<none>') {
      $breadcrumb[] = check_plain($title);
    }
  }

  // Allow other modules to alter breadcrumbs generated by this module.
  drupal_alter('path_breadcrumbs_view', $breadcrumb, $path_breadcrumb, $contexts);
  return $breadcrumb;
}