class EntityPermissionsRouteProvider
Same name in other branches
- 9 core/modules/user/src/Entity/EntityPermissionsRouteProvider.php \Drupal\user\Entity\EntityPermissionsRouteProvider
- 11.x core/modules/user/src/Entity/EntityPermissionsRouteProvider.php \Drupal\user\Entity\EntityPermissionsRouteProvider
Provides routes for the entity permissions form.
Use this class or EntityPermissionsRouteProviderWithCheck as a route provider for an entity type such as Vocabulary. Either one will provide routes for the entity permissions form. The EntityPermissionsRouteProviderWithCheck class provides a custom access check: it denies access if there are no entity-specific permissions. If you know that each entity has permissions, or if the check is too expensive, then use this class.
Hierarchy
- class \Drupal\user\Entity\EntityPermissionsRouteProvider implements \Drupal\Core\Entity\Routing\EntityRouteProviderInterface, \Drupal\Core\Entity\EntityHandlerInterface
Expanded class hierarchy of EntityPermissionsRouteProvider
File
-
core/
modules/ user/ src/ Entity/ EntityPermissionsRouteProvider.php, line 24
Namespace
Drupal\user\EntityView source
class EntityPermissionsRouteProvider implements EntityRouteProviderInterface, EntityHandlerInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new EntityPermissionsRouteProvider.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($container->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
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;
}
/**
* Gets the entity permissions route.
*
* Built only for entity types that are bundles of other entity types and
* define the 'entity-permissions-form' link template.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
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',
], [
// Indicate that Drupal\Core\Entity\Enhancer\EntityBundleRouteEnhancer should
// set the bundle parameter.
'_field_ui' => TRUE,
'parameters' => [
$entity_type_id => [
'type' => "entity:{$entity_type_id}",
'with_config_overrides' => TRUE,
],
],
'_admin_route' => TRUE,
]);
return $route;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
EntityPermissionsRouteProvider::$entityTypeManager | protected | property | The entity type manager. | ||
EntityPermissionsRouteProvider::createInstance | public static | function | Instantiates a new instance of this entity handler. | Overrides EntityHandlerInterface::createInstance | |
EntityPermissionsRouteProvider::getEntityPermissionsRoute | protected | function | Gets the entity permissions route. | 1 | |
EntityPermissionsRouteProvider::getRoutes | public | function | Provides routes for entities. | Overrides EntityRouteProviderInterface::getRoutes | |
EntityPermissionsRouteProvider::__construct | public | function | Constructs a new EntityPermissionsRouteProvider. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.