You are here

function crumbs_Router::reducePath in Crumbs, the Breadcrumbs suite 7.2

Chop off path fragments until we find a valid path.

Parameters

string $path: Starting path or alias

int $depth: Max number of fragments we try to chop off. -1 means no limit.

Return value

string|null

File

lib/Router.php, line 78

Class

crumbs_Router
Wrapper for routing-related Drupal core functions.

Code

function reducePath($path, $depth = -1) {
  $fragments = explode('/', $path);
  while (count($fragments) > 1 && $depth !== 0) {
    array_pop($fragments);
    $parent_path = implode('/', $fragments);
    $parent_item = $this
      ->getRouterItem($parent_path);
    if ($parent_item && $parent_item['href'] === $parent_item['link_path']) {
      return $parent_item['link_path'];
    }
    --$depth;
  }
  return NULL;
}