Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * Contains \Drupal\entity\EntityPermissions.
- */
- namespace Drupal\entity;
- use Drupal\Core\Entity\EntityManagerInterface;
- /**
- * Provides dynamic permissions for participating entity types.
- */
- class EntityPermissions {
- /**
- * The entity manager.
- *
- * @var \Drupal\Core\Entity\EntityManagerInterface
- */
- protected $entityManager;
- /**
- * Creates a new EntityPermissions object.
- *
- * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
- * The entity manager.
- */
- public function __construct(EntityManagerInterface $entity_manager) {
- $this->entityManager = $entity_manager;
- }
- /**
- * Builds a list of permissions for the participating entity types.
- *
- * @return array
- * The permissions.
- * @see \Drupal\user\PermissionHandlerInterface::getPermissions()
- */
- public function buildPermissions() {
- $permissions = [];
- foreach ($this->getParticipatingEntityTypes() as $entity_type) {
- $access_handler_class = $entity_type->getHandlerClass('access');
- $access_handler = new $access_handler_class($entity_type);
- $permissions += $access_handler->buildPermissions();
- }
- return $permissions;
- }
- /**
- * Gets a list of participating entity types.
- *
- * This list includes all entity types that declare access handlers
- * implementing this module's ExtendedEntityAccessControlHandlerInterface.
- *
- * @return \Drupal\Core\Entity\EntityTypeInterface[]
- * The participating entity types.
- */
- protected function getParticipatingEntityTypes() {
- $entity_types = $this->entityManager->getDefinitions();
- $entity_types = array_filter($entity_types, function ($entity_type) {
- $access_handler_class = $entity_type->getHandlerClass('access');
- $interface = '\Drupal\entity\ExtendedEntityAccessControlHandlerInterface';
- return is_subclass_of($access_handler_class, $interface);
- });
- return $entity_types;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement