You are here

public function FarmBreadcrumbBuilder::build in farmOS 2.x

Builds the breadcrumb.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.

Return value

\Drupal\Core\Breadcrumb\Breadcrumb A breadcrumb.

Overrides PathBasedBreadcrumbBuilder::build

File

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

Class

FarmBreadcrumbBuilder
Build farmOS breadcrumbs.

Namespace

Drupal\farm_ui_breadcrumb\Breadcrumb

Code

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;
}