You are here

class FullEntityPermissionProvider in Group 2.0.x

Provides all possible permissions.

Hierarchy

Expanded class hierarchy of FullEntityPermissionProvider

1 string reference to 'FullEntityPermissionProvider'
group_test_plugin.services.yml in tests/modules/group_test_plugin/group_test_plugin.services.yml
tests/modules/group_test_plugin/group_test_plugin.services.yml
2 services use FullEntityPermissionProvider
group.relation_handler.permission_provider.entity_test_as_content in tests/modules/group_test_plugin/group_test_plugin.services.yml
Drupal\group_test_plugin\Plugin\Group\RelationHandler\FullEntityPermissionProvider
group.relation_handler.permission_provider.node_as_content in tests/modules/group_test_plugin/group_test_plugin.services.yml
Drupal\group_test_plugin\Plugin\Group\RelationHandler\FullEntityPermissionProvider

File

tests/modules/group_test_plugin/src/Plugin/Group/RelationHandler/FullEntityPermissionProvider.php, line 12

Namespace

Drupal\group_test_plugin\Plugin\Group\RelationHandler
View source
class FullEntityPermissionProvider implements PermissionProviderInterface {
  use PermissionProviderTrait;

  /**
   * Constructs a new FullEntityPermissionProvider.
   *
   * @param \Drupal\group\Plugin\Group\RelationHandler\PermissionProviderInterface $parent
   *   The parent permission provider.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(PermissionProviderInterface $parent, EntityTypeManagerInterface $entity_type_manager) {
    $this->parent = $parent;
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function getPermission($operation, $target, $scope = 'any') {

    // The view permissions support all scopes here.
    if ($target === 'entity') {
      switch ($operation) {
        case 'view':
          return $this
            ->getEntityViewPermission($scope);
        case 'view unpublished':
          return $this
            ->getEntityViewUnpublishedPermission($scope);
      }
    }
    return $this->parent
      ->getPermission($operation, $target, $scope);
  }

  /**
   * {@inheritdoc}
   */
  public function buildPermissions() {
    $permissions = $this->parent
      ->buildPermissions();

    // Rename view any permissions.
    if ($name = $this->parent
      ->getPermission('view', 'entity')) {
      $permissions[$this
        ->getPermission('view', 'entity')] = $permissions[$name];
      unset($permissions[$name]);
    }
    if ($name = $this->parent
      ->getPermission('view unpublished', 'entity')) {
      $permissions[$this
        ->getPermission('view unpublished', 'entity')] = $permissions[$name];
      unset($permissions[$name]);
    }

    // Support view own permissions.
    $prefix = 'Entity:';
    if ($name = $this
      ->getPermission('view', 'entity', 'own')) {
      $permissions[$name] = $this
        ->buildPermission("{$prefix} View own %entity_type entities");
    }
    if ($name = $this
      ->getPermission('view unpublished', 'entity', 'own')) {
      $permissions[$name] = $this
        ->buildPermission("{$prefix} View own unpublished %entity_type entities");
    }
    return $permissions;
  }

  /**
   * Gets the name of the view permission for the entity.
   *
   * @param string $scope
   *   (optional) Whether the 'any' or 'own' permission name should be returned.
   *   Defaults to 'any'.
   *
   * @return string|false
   *   The permission name or FALSE if it does not apply.
   */
  protected function getEntityViewPermission($scope = 'any') {
    if ($this->definesEntityPermissions) {
      if ($this->implementsOwnerInterface || $scope === 'any') {
        return "view {$scope} {$this->pluginId} entity";
      }
    }
    return FALSE;
  }

  /**
   * Gets the name of the view unpublished permission for the entity.
   *
   * @param string $scope
   *   (optional) Whether the 'any' or 'own' permission name should be returned.
   *   Defaults to 'any'.
   *
   * @return string|false
   *   The permission name or FALSE if it does not apply.
   */
  protected function getEntityViewUnpublishedPermission($scope = 'any') {
    if ($this->definesEntityPermissions) {
      if ($this->implementsOwnerInterface || $scope === 'any') {
        return "view {$scope} unpublished {$this->pluginId} entity";
      }
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FullEntityPermissionProvider::buildPermissions public function Provides a list of group permissions the plugin exposes. Overrides PermissionProviderTrait::buildPermissions
FullEntityPermissionProvider::getEntityViewPermission protected function Gets the name of the view permission for the entity.
FullEntityPermissionProvider::getEntityViewUnpublishedPermission protected function Gets the name of the view unpublished permission for the entity.
FullEntityPermissionProvider::getPermission public function Gets the name of the permission for the given operation, target and scope. Overrides PermissionProviderTrait::getPermission
FullEntityPermissionProvider::__construct public function Constructs a new FullEntityPermissionProvider.
PermissionProviderTrait::$definesEntityPermissions protected property Whether the plugin defines permissions for the target entity type.
PermissionProviderTrait::$entityType protected property The entity type the plugin handler is for.
PermissionProviderTrait::$implementsOwnerInterface protected property Whether the target entity type implements the EntityOwnerInterface.
PermissionProviderTrait::$implementsPublishedInterface protected property Whether the target entity type implements the EntityPublishedInterface.
PermissionProviderTrait::buildPermission protected function Builds a permission with common translation arguments predefined.
PermissionProviderTrait::getAdminPermission public function 4
PermissionProviderTrait::init public function
RelationHandlerTrait::$definition protected property The plugin definition.
RelationHandlerTrait::$entityTypeManager protected property The entity type manager.
RelationHandlerTrait::$groupRelationManager protected property The group relation manager.
RelationHandlerTrait::$parent protected property The parent relation handler in the decorator chain.
RelationHandlerTrait::$pluginId protected property The plugin ID as read from the definition.
RelationHandlerTrait::entityTypeManager protected function Gets the entity type manager service.
RelationHandlerTrait::groupRelationManager protected function Gets the group relation manager service.
RelationHandlerTrait::init public function Aliased as: traitInit