You are here

function path_breadcrumbs_load_variant in Path Breadcrumbs 7.2

Same name and namespace in other branches
  1. 7.3 path_breadcrumbs.module \path_breadcrumbs_load_variant()

Load path breadcrumb variant for page url.

Parameters

$path: Current page url.

Return value

object Path breadcrumb that matches page url.

1 call to path_breadcrumbs_load_variant()
path_breadcrumbs_page_alter in ./path_breadcrumbs.module
Implements hook_page_alter().

File

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

Code

function path_breadcrumbs_load_variant($path) {
  if (!$path) {
    return FALSE;
  }

  // Select all variants matching current path.
  $variants = path_breadcrumbs_load_by_path($path);

  // Check if current path maches variant.
  // When first variant is found - return it.
  foreach ($variants as $breadcrumb) {

    // Replace placeholder in path with '*'.
    // Example: 'node/%node/view' -> 'node/*/view'.
    $matched_path = preg_replace("\n        /\\/%    # start with slash-percent\n        [^\\/]+  # all symbols except for the slash\n        /x", '/*', $breadcrumb->path);
    if (drupal_match_path($path, $matched_path)) {

      // Load breadcrumbs' contexts from current path.
      $contexts = path_breadcrumbs_get_contexts_from_arguments($breadcrumb->arguments);

      // If breadcrumb contains broken context
      // it means that unable to load context from URL.
      if (isset($contexts['broken_context'])) {
        continue;
      }

      // Check if breadcrumb is accessable.
      if (!empty($breadcrumb->access)) {
        $access = ctools_access($breadcrumb->access, $contexts);
        if (!$access) {
          continue;
        }
      }

      // Build suitable breadcrumb variant.
      return _path_breadcrumbs_build_breadcrumbs($breadcrumb, $contexts);
    }
  }
  return FALSE;
}