You are here

function _custom_breadcrumbs_create_crumb_items in Custom Breadcrumbs 6.2

Same name and namespace in other branches
  1. 7.2 custom_breadcrumbs.module \_custom_breadcrumbs_create_crumb_items()

Creates one or more crumb items out of a custom breadcrumb definition line.

Parameters

$title: Title string of the custom breadcrumb definition (after token replacement).

$original_path: Path string of the custom breadcrumb definition (after token replacment) which may contain a special identifier.

$attributes: An array of additional attributes for the breadcrumb item.

Return value

An array of one or multiple crumb items. In most cases, especially without an identifier, it is only an array of one item.

1 call to _custom_breadcrumbs_create_crumb_items()
_custom_breadcrumbs_get_trail_items in ./custom_breadcrumbs.module
Builds the trail items for a given breadcrumb specification.

File

./custom_breadcrumbs.module, line 575
Provide custom breadcrumbs for node-type pages and base functionality for submodules to add custom breadcrumbs for other types of pages.

Code

function _custom_breadcrumbs_create_crumb_items($title, $original_path, $attributes = array()) {

  // The array to return.
  $crumbs = array();

  // Decode title to properly handle special characters.
  $original_title = decode_entities($title);

  // Extract title attribute, if present.
  $title_parts = explode("|", $original_title, 2);
  $title = $title_parts[0];
  if (isset($title_parts[1])) {
    $attributes['attributes']['title'] = $title_parts[1];
  }

  // Collapse double slashes to one.
  $original_path = preg_replace('/\\/+/', '/', $original_path);

  // Removing leading and trailing slashes.
  $original_path = preg_replace('/^\\/|\\/+$/', '', $original_path);
  $path_parts = explode("|", $original_path, 2);
  $values = NULL;

  // Assume an identifier is present since there are some identifiers that don't use the pipe operator.
  $identifier = trim($path_parts[0]);
  $path = isset($path_parts[1]) ? $path_parts[1] : NULL;

  // Replace identifiers provided by modules implementing hook_cb_identifier_values.
  $obj = array(
    'title' => $title,
    'path' => $path,
    'attributes' => $attributes,
  );
  foreach (module_implements('cb_identifier_values') as $module) {
    $values = module_invoke($module, 'cb_identifier_values', $identifier, $obj);
    if (isset($values)) {
      break;
    }
  }
  if (isset($values)) {

    // Ease return values for callbacks.
    if (!is_array($values)) {
      $crumbs[] = array(
        'crumb' => $values,
        'title' => $title,
        'href' => $path,
      );
    }
    elseif (isset($values['crumb']) || isset($values['title']) || isset($values['href'])) {
      $crumbs[] = $values;
    }
    else {
      $crumbs = $values;
    }
  }
  else {

    // Use original path if no pipe was given.
    if (!isset($path)) {
      $path = $original_path;
    }
    if ($path != '<none>') {
      $options = parse_url($path);
      $options = array_merge($options, $attributes);
      $crumbs[] = array(
        'crumb' => l($title, $options['path'], $options),
        'title' => $title,
        'href' => $options['path'],
      );
    }
    else {
      $crumbs[] = array(
        'crumb' => $title,
        'title' => $title,
      );
    }
  }
  return $crumbs;
}