You are here

class EntityPermissions in Entity API 8

Generates entity permissions via their permission providers.

Hierarchy

Expanded class hierarchy of EntityPermissions

See also

\Drupal\entity\EntityPermissionProvider

\Drupal\entity\UncacheableEntityPermissionProvider

File

src/EntityPermissions.php, line 15

Namespace

Drupal\entity
View source
class EntityPermissions implements ContainerInjectionInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a new EntityPermissions object.
   *
   * @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 create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager'));
  }

  /**
   * Builds a list of permissions for the participating entity types.
   *
   * @return array
   *   The permissions.
   */
  public function buildPermissions() {
    $permissions = [];

    /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type) {
      if ($entity_type
        ->hasHandlerClass('permission_provider')) {
        $permission_provider_class = $entity_type
          ->getHandlerClass('permission_provider');
        $permission_provider = $this->entityTypeManager
          ->createHandlerInstance($permission_provider_class, $entity_type);
        $permissions += $permission_provider
          ->buildPermissions($entity_type);
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityPermissions::$entityTypeManager protected property The entity type manager.
EntityPermissions::buildPermissions public function Builds a list of permissions for the participating entity types.
EntityPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
EntityPermissions::__construct public function Constructs a new EntityPermissions object.