class TMGMTLocalBreadcrumbBuilder

A custom Local task item breadcrumb builder.

Hierarchy

  • class \Drupal\tmgmt_local\Menu\TMGMTLocalBreadcrumbBuilder implements \Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface uses \Drupal\Core\StringTranslation\StringTranslationTrait

Expanded class hierarchy of TMGMTLocalBreadcrumbBuilder

1 string reference to 'TMGMTLocalBreadcrumbBuilder'
tmgmt_local.services.yml in translators/tmgmt_local/tmgmt_local.services.yml
translators/tmgmt_local/tmgmt_local.services.yml

File

translators/tmgmt_local/src/Menu/TMGMTLocalBreadcrumbBuilder.php, line 16

Namespace

Drupal\tmgmt_local\Menu
View source
class TMGMTLocalBreadcrumbBuilder implements BreadcrumbBuilderInterface {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    if (strpos($route_match
      ->getRouteName(), 'view.tmgmt_local_manage_translate_task') === 0 || strpos($route_match
      ->getRouteName(), 'view.tmgmt_local_task_overview') === 0 || $route_match
      ->getParameter('tmgmt_local_task') instanceof LocalTaskInterface || $route_match
      ->getParameter('tmgmt_local_task_item') instanceof LocalTaskItemInterface) {
      return TRUE;
    }
    return FALSE;
  }

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

    // Add links to administration, and translation to the breadcrumb.
    if (\Drupal::config('tmgmt_local.settings')
      ->get('use_admin_theme') || strpos($route_match
      ->getRouteObject()
      ->getPath(), '/manage-translate') === 0) {
      $breadcrumb
        ->addLink(Link::createFromRoute($this
        ->t('Administration'), 'system.admin'));
      $breadcrumb
        ->addLink(Link::createFromRoute($this
        ->t('Translation'), 'tmgmt.admin_tmgmt'));
    }
    if ($route_match
      ->getParameter('tmgmt_local_task') instanceof LocalTaskInterface || $route_match
      ->getParameter('tmgmt_local_task_item') instanceof LocalTaskItemInterface) {
      $breadcrumb
        ->addLink(Link::createFromRoute($this
        ->t('Local Tasks'), 'view.tmgmt_local_task_overview.unassigned'));
      if ($route_match
        ->getParameter('tmgmt_local_task_item') instanceof LocalTaskItemInterface) {

        /** @var LocalTaskItemInterface $local_task_item */
        $local_task_item = $route_match
          ->getParameter('tmgmt_local_task_item');
        $breadcrumb
          ->addCacheableDependency($local_task_item);
        $breadcrumb
          ->addLink(Link::createFromRoute($local_task_item
          ->getTask()
          ->label(), 'entity.tmgmt_local_task.canonical', array(
          'tmgmt_local_task' => $local_task_item
            ->getTask()
            ->id(),
        )));
      }
    }
    return $breadcrumb;
  }

}

Members