You are here

class IngredientBreadcrumbBuilder in Recipe 8.2

Builds breadcrumbs for Ingredient entities.

Hierarchy

Expanded class hierarchy of IngredientBreadcrumbBuilder

1 string reference to 'IngredientBreadcrumbBuilder'
ingredient.services.yml in modules/ingredient/ingredient.services.yml
modules/ingredient/ingredient.services.yml
1 service uses IngredientBreadcrumbBuilder
ingredient.breadcrumb in modules/ingredient/ingredient.services.yml
Drupal\ingredient\IngredientBreadcrumbBuilder

File

modules/ingredient/src/IngredientBreadcrumbBuilder.php, line 14

Namespace

Drupal\ingredient
View source
class IngredientBreadcrumbBuilder implements BreadcrumbBuilderInterface {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    $ingredient = $route_match
      ->getParameter('ingredient');
    $match = $ingredient instanceof IngredientInterface;
    return $match;
  }

  /**
   * {@inheritdoc}
   */
  public function build(RouteMatchInterface $route_match) {
    $breadcrumb = new Breadcrumb();
    $links[] = Link::createFromRoute($this
      ->t('Home'), '<front>');
    $links[] = Link::createFromRoute($this
      ->t('Ingredients'), 'ingredient.landing_page');
    $breadcrumb
      ->setLinks($links);
    $breadcrumb
      ->addCacheContexts([
      'route',
    ]);
    return $breadcrumb;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IngredientBreadcrumbBuilder::applies public function Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface::applies
IngredientBreadcrumbBuilder::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.