You are here

class FarmBreadcrumbBuilder in farmOS 2.x

Build farmOS breadcrumbs.

Hierarchy

Expanded class hierarchy of FarmBreadcrumbBuilder

1 string reference to 'FarmBreadcrumbBuilder'
farm_ui_breadcrumb.services.yml in modules/core/ui/breadcrumb/farm_ui_breadcrumb.services.yml
modules/core/ui/breadcrumb/farm_ui_breadcrumb.services.yml
1 service uses FarmBreadcrumbBuilder
farm_ui_breadcrumb.breadcrumb in modules/core/ui/breadcrumb/farm_ui_breadcrumb.services.yml
Drupal\farm_ui_breadcrumb\Breadcrumb\FarmBreadcrumbBuilder

File

modules/core/ui/breadcrumb/src/Breadcrumb/FarmBreadcrumbBuilder.php, line 13

Namespace

Drupal\farm_ui_breadcrumb\Breadcrumb
View source
class FarmBreadcrumbBuilder extends PathBasedBreadcrumbBuilder {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function build(RouteMatchInterface $route_match) {
    $breadcrumb = parent::build($route_match);

    // Get parameters.
    $parameters = $route_match
      ->getParameters();

    // Add links based on the route.
    switch ($route_match
      ->getRouteName()) {

      // Asset pages.
      case 'entity.asset.canonical':

        /** @var \Drupal\asset\Entity\AssetInterface $asset */
        $asset = $parameters
          ->get('asset');
        $breadcrumb
          ->addCacheableDependency($asset);
        $breadcrumb
          ->addLink(Link::createFromRoute($this
          ->t('Records'), '<front>'));
        $breadcrumb
          ->addLink(Link::createFromRoute($this
          ->t('Assets'), 'view.farm_asset.page'));
        $breadcrumb
          ->addLink(Link::createFromRoute($asset
          ->getBundleLabel(), 'view.farm_asset.page_type', [
          'arg_0' => $asset
            ->bundle(),
        ]));
        break;

      // Log pages.
      case 'entity.log.canonical':

        /** @var \Drupal\log\Entity\LogInterface $log */
        $log = $parameters
          ->get('log');
        $breadcrumb
          ->addCacheableDependency($log);
        $breadcrumb
          ->addLink(Link::createFromRoute($this
          ->t('Records'), '<front>'));
        $breadcrumb
          ->addLink(Link::createFromRoute($this
          ->t('Logs'), 'view.farm_log.page'));
        $breadcrumb
          ->addLink(Link::createFromRoute($log
          ->getBundleLabel(), 'view.farm_log.page_type', [
          'arg_0' => $log
            ->bundle(),
        ]));
        break;

      // Plan pages.
      case 'entity.plan.canonical':

        /** @var \Drupal\plan\Entity\PlanInterface $plan */
        $plan = $parameters
          ->get('plan');
        $breadcrumb
          ->addCacheableDependency($plan);
        $breadcrumb
          ->addLink(Link::createFromRoute($this
          ->t('Plans'), 'view.farm_plan.page'));
        $breadcrumb
          ->addLink(Link::createFromRoute($plan
          ->getBundleLabel(), 'view.farm_plan.page_type', [
          'arg_0' => $plan
            ->bundle(),
        ]));
        break;
    }

    // This breadcrumb builder is based on a route parameter, and hence it
    // depends on the 'route' cache context.
    $breadcrumb
      ->addCacheContexts([
      'route',
    ]);
    return $breadcrumb;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FarmBreadcrumbBuilder::build public function Builds the breadcrumb. Overrides PathBasedBreadcrumbBuilder::build
PathBasedBreadcrumbBuilder::$accessManager protected property The menu link access service.
PathBasedBreadcrumbBuilder::$config protected property Site config object.
PathBasedBreadcrumbBuilder::$context protected property The router request context.
PathBasedBreadcrumbBuilder::$currentPath protected property The current path service.
PathBasedBreadcrumbBuilder::$currentUser protected property The current user object.
PathBasedBreadcrumbBuilder::$pathMatcher protected property The patch matcher service.
PathBasedBreadcrumbBuilder::$pathProcessor protected property The inbound path processor.
PathBasedBreadcrumbBuilder::$router protected property The dynamic router service.
PathBasedBreadcrumbBuilder::$titleResolver protected property The title resolver.
PathBasedBreadcrumbBuilder::applies public function Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface::applies
PathBasedBreadcrumbBuilder::getRequestForPath protected function Matches a path in the router.
PathBasedBreadcrumbBuilder::__construct public function Constructs the PathBasedBreadcrumbBuilder.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
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.