You are here

class CalculatedGroupPermissionsItem in Group 8

Same name and namespace in other branches
  1. 2.0.x src/Access/CalculatedGroupPermissionsItem.php \Drupal\group\Access\CalculatedGroupPermissionsItem

Represents a single entry for the calculated group permissions.

Hierarchy

Expanded class hierarchy of CalculatedGroupPermissionsItem

See also

\Drupal\group\Access\ChainGroupPermissionCalculator

5 files declare their use of CalculatedGroupPermissionsItem
CalculatedGroupPermissionsItemTest.php in tests/src/Unit/CalculatedGroupPermissionsItemTest.php
CalculatedGroupPermissionsTest.php in tests/src/Unit/CalculatedGroupPermissionsTest.php
GroupPermissionCheckerTest.php in tests/src/Unit/GroupPermissionCheckerTest.php
GroupPermissionHashGeneratorTest.php in tests/src/Unit/GroupPermissionHashGeneratorTest.php
RefinableCalculatedGroupPermissionsTest.php in tests/src/Unit/RefinableCalculatedGroupPermissionsTest.php

File

src/Access/CalculatedGroupPermissionsItem.php, line 10

Namespace

Drupal\group\Access
View source
class CalculatedGroupPermissionsItem implements CalculatedGroupPermissionsItemInterface {

  /**
   * The scope name.
   *
   * @var string
   */
  protected $scope;

  /**
   * The identifier.
   *
   * @var string|int
   */
  protected $identifier;

  /**
   * The permission names.
   *
   * @var string[]
   */
  protected $permissions;

  /**
   * Whether this entry grants admin rights for the given scope.
   *
   * @var bool
   */
  protected $isAdmin;

  /**
   * Constructs a new CalculatedGroupPermissionsItem.
   *
   * @param string $scope
   *   The scope name.
   * @param string|int $identifier
   *   The identifier within the scope.
   * @param string[] $permissions
   *   The permission names.
   * @param bool $is_admin
   *   (optional) Whether the item grants admin privileges.
   */
  public function __construct($scope, $identifier, $permissions, $is_admin = NULL) {
    $this->scope = $scope;
    $this->identifier = $identifier;
    $this->permissions = array_unique($permissions);

    // @todo Rework for group 8.2.x to no longer use the admin permission.
    // @todo Do make flag default to FALSE and pass role's isAdmin flag instead.
    $this->isAdmin = isset($is_admin) ? $is_admin : in_array('administer group', $permissions, TRUE);
  }

  /**
   * {@inheritdoc}
   */
  public function getScope() {
    return $this->scope;
  }

  /**
   * {@inheritdoc}
   */
  public function getIdentifier() {
    return $this->identifier;
  }

  /**
   * {@inheritdoc}
   */
  public function getPermissions() {
    return $this->permissions;
  }

  /**
   * {@inheritdoc}
   */
  public function isAdmin() {
    return $this->isAdmin;
  }

  /**
   * {@inheritdoc}
   */
  public function hasPermission($permission) {
    return $this
      ->isAdmin() || in_array($permission, $this->permissions, TRUE);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CalculatedGroupPermissionsItem::$identifier protected property The identifier.
CalculatedGroupPermissionsItem::$isAdmin protected property Whether this entry grants admin rights for the given scope.
CalculatedGroupPermissionsItem::$permissions protected property The permission names.
CalculatedGroupPermissionsItem::$scope protected property The scope name.
CalculatedGroupPermissionsItem::getIdentifier public function Returns the identifier within the scope. Overrides CalculatedGroupPermissionsItemInterface::getIdentifier
CalculatedGroupPermissionsItem::getPermissions public function Returns the permissions for the calculated permissions item. Overrides CalculatedGroupPermissionsItemInterface::getPermissions
CalculatedGroupPermissionsItem::getScope public function Returns the scope of the calculated permissions item. Overrides CalculatedGroupPermissionsItemInterface::getScope
CalculatedGroupPermissionsItem::hasPermission public function Returns whether this item has a given permission. Overrides CalculatedGroupPermissionsItemInterface::hasPermission
CalculatedGroupPermissionsItem::isAdmin public function Returns whether this item grants admin privileges in its scope. Overrides CalculatedGroupPermissionsItemInterface::isAdmin
CalculatedGroupPermissionsItem::__construct public function Constructs a new CalculatedGroupPermissionsItem.
CalculatedGroupPermissionsItemInterface::SCOPE_GROUP constant The scope for group based permissions (e.g.: memberships).
CalculatedGroupPermissionsItemInterface::SCOPE_GROUP_TYPE constant The scope for group type based permissions (e.g.: anonymous or outsider).