You are here

class PrettyPathBreadcrumb in Facets Pretty Paths 8

Pretty Paths breadcrumb builder.

Hierarchy

Expanded class hierarchy of PrettyPathBreadcrumb

1 string reference to 'PrettyPathBreadcrumb'
facets_pretty_paths.services.yml in ./facets_pretty_paths.services.yml
facets_pretty_paths.services.yml
1 service uses PrettyPathBreadcrumb
facets_pretty_paths.breadcrumb in ./facets_pretty_paths.services.yml
Drupal\facets_pretty_paths\PrettyPathBreadcrumb

File

src/PrettyPathBreadcrumb.php, line 15

Namespace

Drupal\facets_pretty_paths
View source
class PrettyPathBreadcrumb implements BreadcrumbBuilderInterface {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    if ($route_match
      ->getParameter('facets_query')) {
      return TRUE;
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function build(RouteMatchInterface $route_match) {
    $breadcrumb = new Breadcrumb();
    $breadcrumb
      ->addCacheContexts([
      'route',
    ]);
    $route_object = $route_match
      ->getRouteObject();
    $route_without_facets_query = explode('/{facets_query}', $route_object
      ->getPath())[0];
    $request = \Drupal::request();
    $title = \Drupal::service('title_resolver')
      ->getTitle($request, $route_object);
    $url = Url::fromUserInput($route_without_facets_query);
    $links[] = Link::createFromRoute($this
      ->t('Home'), '<front>');
    $links[] = Link::fromTextAndUrl($title, $url);
    return $breadcrumb
      ->setLinks($links);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PrettyPathBreadcrumb::applies public function Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface::applies
PrettyPathBreadcrumb::build public function Builds the breadcrumb. Overrides BreadcrumbBuilderInterface::build
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.