EntityPermissionsRouteProvider.php in Drupal 10
File
core/modules/user/src/Entity/EntityPermissionsRouteProvider.php
View source
<?php
namespace Drupal\user\Entity;
use Drupal\Core\Entity\EntityHandlerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Routing\EntityRouteProviderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class EntityPermissionsRouteProvider implements EntityRouteProviderInterface, EntityHandlerInterface {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($container
->get('entity_type.manager'));
}
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = new RouteCollection();
$entity_type_id = $entity_type
->id();
if ($entity_permissions_route = $this
->getEntityPermissionsRoute($entity_type)) {
$collection
->add("entity.{$entity_type_id}.entity_permissions_form", $entity_permissions_route);
}
return $collection;
}
protected function getEntityPermissionsRoute(EntityTypeInterface $entity_type) : ?Route {
if (!$entity_type
->hasLinkTemplate('entity-permissions-form')) {
return NULL;
}
if (!($bundle_of_id = $entity_type
->getBundleOf())) {
return NULL;
}
$entity_type_id = $entity_type
->id();
$route = new Route($entity_type
->getLinkTemplate('entity-permissions-form'), [
'_title' => 'Manage permissions',
'_form' => 'Drupal\\user\\Form\\EntityPermissionsForm',
'entity_type_id' => $bundle_of_id,
'bundle_entity_type' => $entity_type_id,
], [
'_permission' => 'administer permissions',
], [
'_field_ui' => TRUE,
'parameters' => [
$entity_type_id => [
'type' => "entity:{$entity_type_id}",
'with_config_overrides' => TRUE,
],
],
'_admin_route' => TRUE,
]);
return $route;
}
}