InvoiceRouteProvider.php in Commerce Invoice 8.2
File
src/InvoiceRouteProvider.php
View source
<?php
namespace Drupal\commerce_invoice;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
class InvoiceRouteProvider extends AdminHtmlRouteProvider {
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
$entity_type_id = $entity_type
->id();
if ($download_route = $this
->getDownloadRoute($entity_type)) {
$collection
->add("entity.{$entity_type_id}.download", $download_route);
}
if ($invoice_payment_route = $this
->getInvoicePaymentFormRoute($entity_type)) {
$collection
->add("entity.{$entity_type_id}.payment_form", $invoice_payment_route);
}
return $collection;
}
protected function getCanonicalRoute(EntityTypeInterface $entity_type) {
$route = parent::getCanonicalRoute($entity_type);
$route
->setDefault('_entity_view', 'commerce_invoice.admin');
return $route;
}
protected function getDownloadRoute(EntityTypeInterface $entity_type) {
if ($entity_type
->hasLinkTemplate('download')) {
$entity_type_id = $entity_type
->id();
$route = new Route($entity_type
->getLinkTemplate('download'));
$route
->addDefaults([
'_controller' => '\\Drupal\\commerce_invoice\\Controller\\InvoiceController::download',
])
->setRequirement('_entity_access', "{$entity_type_id}.view")
->setOption('parameters', [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
],
]);
if ($this
->getEntityTypeIdKeyType($entity_type) === 'integer') {
$route
->setRequirement($entity_type_id, '\\d+');
}
return $route;
}
}
protected function getInvoicePaymentFormRoute(EntityTypeInterface $entity_type) {
if ($entity_type
->hasLinkTemplate('payment-form')) {
$route = new Route($entity_type
->getLinkTemplate('payment-form'));
$entity_type_id = $entity_type
->id();
$route
->setDefaults([
'_form' => '\\Drupal\\commerce_invoice\\Form\\InvoicePaymentForm',
])
->setRequirement('_entity_access', "{$entity_type_id}.update")
->setOption('parameters', [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
],
]);
if ($this
->getEntityTypeIdKeyType($entity_type) === 'integer') {
$route
->setRequirement($entity_type_id, '\\d+');
}
return $route;
}
}
}