Commit 41456f5f authored by Robin De Herdt's avatar Robin De Herdt Committed by Szczepan Musiał
Browse files

Issue #3198500: Allow fallback on lower priority breadcrumb builders

parent bc44b762
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -156,6 +156,10 @@ class BreadcrumbBuilder implements BreadcrumbBuilderInterface {
      return FALSE;
    }

    if (!$this->matchPaths($route_match) && !$this->matchEntity($route_match)) {
      return FALSE;
    }

    return TRUE;
  }

@@ -454,6 +458,37 @@ class BreadcrumbBuilder implements BreadcrumbBuilderInterface {
    return FALSE;
  }

  /**
   * Check breadcrumbs by entity.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   Route match.
   *
   * @return bool
   *   True if a match was found, false otherwise.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  protected function matchEntity(RouteMatchInterface $route_match) {
    $params = $route_match->getParameters()->all();

    $entityTypeIds = array_keys($params);
    $entityTypeId = reset($entityTypeIds);

    $breadcrumbSettings = $this->entityTypeManager->getStorage('custom_breadcrumbs')
      ->loadByProperties([
        'entityType' => $entityTypeId,
        'status' => TRUE,
        'type' => 1,
      ]);

    $this->filterPerBundle($breadcrumbSettings, $route_match);
    $this->filterPerLanguage($breadcrumbSettings);

    return !empty($breadcrumbSettings);
  }

  /**
   * Helper method to trim title.
   *