You are here

protected function BreadcrumbBuilder::matchPaths in Custom Breadcrumbs 1.x

Check breadcrumbs by path.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: Route match.

Return value

bool|\Drupal\Core\Entity\EntityInterface CustomBreadcrumb entity or False.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to BreadcrumbBuilder::matchPaths()
BreadcrumbBuilder::build in src/BreadcrumbBuilder.php
Builds the breadcrumb.

File

src/BreadcrumbBuilder.php, line 424

Class

BreadcrumbBuilder
Class BreadcrumbBuilder.

Namespace

Drupal\custom_breadcrumbs

Code

protected function matchPaths(RouteMatchInterface $route_match) {
  $breadcrumbSettingsIDs = $this->entityTypeManager
    ->getStorage('custom_breadcrumbs')
    ->getQuery()
    ->condition('pathPattern', '', '<>')
    ->condition('status', TRUE)
    ->execute();
  $breadcrumbSettings = CustomBreadcrumbs::loadMultiple(array_keys($breadcrumbSettingsIDs));
  $url = Url::fromRouteMatch($route_match);
  foreach ($breadcrumbSettings as $breadcrumbSetting) {
    $langcode = $breadcrumbSetting
      ->get('language') != 'und' ? $breadcrumbSetting
      ->get('language') : NULL;
    $aliases = [];
    $aliases[] = $this->aliasManager
      ->getAliasByPath('/' . $url
      ->getInternalPath(), $langcode);
    $aliases[] = '/' . $url
      ->getInternalPath();
    $pattern = $breadcrumbSetting
      ->get('pathPattern');
    foreach ($aliases as $alias) {
      if ($this->pathMatcher
        ->matchPath($alias, $pattern)) {
        return $breadcrumbSetting;
      }
    }
  }
  return FALSE;
}