You are here

class InvoiceBreadcrumbBuilder in Commerce Invoice 8.2

Defines the Commerce Invoice breadcrumb builder.

Hierarchy

Expanded class hierarchy of InvoiceBreadcrumbBuilder

1 string reference to 'InvoiceBreadcrumbBuilder'
commerce_invoice.services.yml in ./commerce_invoice.services.yml
commerce_invoice.services.yml
1 service uses InvoiceBreadcrumbBuilder
commerce_invoice.breadcrumb in ./commerce_invoice.services.yml
Drupal\commerce_invoice\InvoiceBreadcrumbBuilder

File

src/InvoiceBreadcrumbBuilder.php, line 13

Namespace

Drupal\commerce_invoice
View source
class InvoiceBreadcrumbBuilder extends PathBasedBreadcrumbBuilder {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {

    // This breadcrumb builder applies only when an invoice corresponds to a
    // single order.
    $invoice = $route_match
      ->getParameter('commerce_invoice');
    return $invoice instanceof InvoiceInterface && $invoice
      ->get('orders')
      ->count() === 1;
  }

  /**
   * {@inheritdoc}
   */
  public function build(RouteMatchInterface $route_match) {
    $current_path_info = $this->context
      ->getPathInfo();

    /** @var \Drupal\commerce_invoice\Entity\InvoiceInterface $invoice */
    $invoice = $route_match
      ->getParameter('commerce_invoice');
    $path = $invoice
      ->toUrl('collection')
      ->getInternalPath();
    $this->context
      ->setPathInfo('/' . trim($path, '/') . '/' . $invoice
      ->id());
    $breadcrumb = parent::build($route_match);

    // Restore the initial request path info.
    $this->context
      ->setPathInfo($current_path_info);
    return $breadcrumb;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InvoiceBreadcrumbBuilder::applies public function Whether this breadcrumb builder should be used to build the breadcrumb. Overrides PathBasedBreadcrumbBuilder::applies
InvoiceBreadcrumbBuilder::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::getRequestForPath protected function Matches a path in the router.
PathBasedBreadcrumbBuilder::__construct public function Constructs the PathBasedBreadcrumbBuilder.
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.