class EntityPermissionsRouteProvider

Same name and namespace in other branches
  1. 9 core/modules/user/src/Entity/EntityPermissionsRouteProvider.php \Drupal\user\Entity\EntityPermissionsRouteProvider
  2. 10 core/modules/user/src/Entity/EntityPermissionsRouteProvider.php \Drupal\user\Entity\EntityPermissionsRouteProvider

Provides routes for the entity permissions form.

Use this class as a route provider for an entity type such as Vocabulary. It will provide routes for the entity permissions form.

Hierarchy

Expanded class hierarchy of EntityPermissionsRouteProvider

6 files declare their use of EntityPermissionsRouteProvider
BlockContentType.php in core/modules/block_content/src/Entity/BlockContentType.php
CommentType.php in core/modules/comment/src/Entity/CommentType.php
ContactForm.php in core/modules/contact/src/Entity/ContactForm.php
MediaType.php in core/modules/media/src/Entity/MediaType.php
NodeType.php in core/modules/node/src/Entity/NodeType.php

... See full list

File

core/modules/user/src/Entity/EntityPermissionsRouteProvider.php, line 19

Namespace

Drupal\user\Entity
View 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.