class InvoiceBreadcrumbBuilder in Commerce Invoice 8.2
Defines the Commerce Invoice breadcrumb builder.
Hierarchy
- class \Drupal\system\PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface uses StringTranslationTrait
- class \Drupal\commerce_invoice\InvoiceBreadcrumbBuilder uses StringTranslationTrait
Expanded class hierarchy of InvoiceBreadcrumbBuilder
1 string reference to 'InvoiceBreadcrumbBuilder'
1 service uses InvoiceBreadcrumbBuilder
File
- src/
InvoiceBreadcrumbBuilder.php, line 13
Namespace
Drupal\commerce_invoiceView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InvoiceBreadcrumbBuilder:: |
public | function |
Whether this breadcrumb builder should be used to build the breadcrumb. Overrides PathBasedBreadcrumbBuilder:: |
|
InvoiceBreadcrumbBuilder:: |
public | function |
Builds the breadcrumb. Overrides PathBasedBreadcrumbBuilder:: |
|
PathBasedBreadcrumbBuilder:: |
protected | property | The menu link access service. | |
PathBasedBreadcrumbBuilder:: |
protected | property | Site config object. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The router request context. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The current path service. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The current user object. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The patch matcher service. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The inbound path processor. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The dynamic router service. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The title resolver. | |
PathBasedBreadcrumbBuilder:: |
protected | function | Matches a path in the router. | |
PathBasedBreadcrumbBuilder:: |
public | function | Constructs the PathBasedBreadcrumbBuilder. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |