You are here

class TMGMTLocalBreadcrumbBuilder in Translation Management Tool 8

A custom Local task item breadcrumb builder.

Hierarchy

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
1 service uses TMGMTLocalBreadcrumbBuilder
tmgmt_local.tmgmt_local_task_item.breadcrumb in translators/tmgmt_local/tmgmt_local.services.yml
Drupal\tmgmt_local\Menu\TMGMTLocalBreadcrumbBuilder

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

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