contacts-8.x-1.x-dev/modules/dbs/src/DBSStatusHtmlRouteProvider.php
modules/dbs/src/DBSStatusHtmlRouteProvider.php
<?php
namespace Drupal\contacts_dbs;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
/**
* Provides routes for DBS Status entities.
*
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class DBSStatusHtmlRouteProvider extends AdminHtmlRouteProvider {
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
$entity_type_id = $entity_type->id();
if ($archive_route = $this->getArchiveFormRoute($entity_type)) {
$collection->add("entity.{$entity_type_id}.archive_form", $archive_route);
}
return $collection;
}
/**
* Gets the archive-form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getArchiveFormRoute(EntityTypeInterface $entity_type) {
if ($entity_type->hasLinkTemplate('archive-form')) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('archive-form'));
$route
->addDefaults([
'_entity_form' => "{$entity_type_id}.archive",
'_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title',
])
->setRequirement('_entity_access', "{$entity_type_id}.archive")
->setRequirement($entity_type_id, '\d+')
->setOption('parameters', [
$entity_type_id => ['type' => 'entity:' . $entity_type_id],
]);
return $route;
}
}
}
