AccessTokenRouteProvider.php in Access unpublished 8
File
src/Routing/AccessTokenRouteProvider.php
View source
<?php
namespace Drupal\access_unpublished\Routing;
use Drupal\access_unpublished\Controller\AccessTokenController;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\EntityRouteProviderInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class AccessTokenRouteProvider implements EntityRouteProviderInterface {
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = new RouteCollection();
$entity_type_id = $entity_type
->id();
if ($add_page_route = $this
->getRenewRoute($entity_type)) {
$collection
->add("entity.{$entity_type_id}.renew", $add_page_route);
}
if ($add_page_route = $this
->getDeleteRoute($entity_type)) {
$collection
->add("entity.{$entity_type_id}.delete", $add_page_route);
}
return $collection;
}
protected function getRenewRoute(EntityTypeInterface $entity_type) {
$entity_type_id = $entity_type
->id();
$route = new Route($entity_type
->getLinkTemplate('renew'));
$route
->setDefault('_controller', AccessTokenController::class . '::renew')
->setRequirement('_permission', 'renew token')
->setOption('parameters', [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
],
]);
return $route;
}
protected function getDeleteRoute(EntityTypeInterface $entity_type) {
$entity_type_id = $entity_type
->id();
$route = new Route($entity_type
->getLinkTemplate('delete'));
$route
->setDefault('_controller', AccessTokenController::class . '::delete')
->setRequirement('_permission', 'delete token')
->setOption('parameters', [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
],
]);
return $route;
}
}