You are here

class JobItemBreadcrumbBuilder in Translation Management Tool 8

A custom Job item breadcrumb builder.

Hierarchy

Expanded class hierarchy of JobItemBreadcrumbBuilder

1 string reference to 'JobItemBreadcrumbBuilder'
tmgmt.services.yml in ./tmgmt.services.yml
tmgmt.services.yml
1 service uses JobItemBreadcrumbBuilder
tmgmt.tmgmt_job_item.breadcrumb in ./tmgmt.services.yml
Drupal\tmgmt\Menu\JobItemBreadcrumbBuilder

File

src/Menu/JobItemBreadcrumbBuilder.php, line 15

Namespace

Drupal\tmgmt\Menu
View source
class JobItemBreadcrumbBuilder implements BreadcrumbBuilderInterface {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    if ($route_match
      ->getRouteName() == 'entity.tmgmt_job_item.canonical' && $route_match
      ->getParameter('tmgmt_job_item') instanceof JobItemInterface) {
      return TRUE;
    }
  }

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

    /** @var JobItemInterface $job_item */
    $job_item = $route_match
      ->getParameter('tmgmt_job_item');
    $breadcrumb
      ->addCacheableDependency($job_item);

    // Add links to administration, translation, job overview and job to the
    // breadcrumb.
    $breadcrumb
      ->addLink(Link::createFromRoute($this
      ->t('Administration'), 'system.admin'));
    $breadcrumb
      ->addLink(Link::createFromRoute($this
      ->t('Translation'), 'tmgmt.admin_tmgmt'));
    $breadcrumb
      ->addLink(Link::createFromRoute($this
      ->t('Job overview'), 'view.tmgmt_job_overview.page_1'));
    $breadcrumb
      ->addLink(Link::createFromRoute($job_item
      ->getJob()
      ->label(), 'entity.tmgmt_job.canonical', array(
      'tmgmt_job' => $job_item
        ->getJobId(),
    )));
    return $breadcrumb;
  }

}

Members

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