interface RoleInterface

Same name and namespace in other branches
  1. 11.x core/modules/user/src/RoleInterface.php \Drupal\user\RoleInterface
  2. 9 core/modules/user/src/RoleInterface.php \Drupal\user\RoleInterface
  3. 10 core/modules/user/src/RoleInterface.php \Drupal\user\RoleInterface

Provides an interface defining a user role entity.

Hierarchy

Expanded class hierarchy of RoleInterface

All classes that implement RoleInterface

Related topics

102 files declare their use of RoleInterface
AccessDeniedTest.php in core/modules/system/tests/src/Functional/System/AccessDeniedTest.php
ActionResourceTestBase.php in core/modules/system/tests/src/Functional/Rest/ActionResourceTestBase.php
ActionTest.php in core/modules/system/tests/src/Kernel/Action/ActionTest.php
ActionTest.php in core/modules/jsonapi/tests/src/Functional/ActionTest.php
AnonymousUserSessionTest.php in core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php

... See full list

File

core/modules/user/src/RoleInterface.php, line 13

Namespace

Drupal\user
View source
interface RoleInterface extends ConfigEntityInterface {
  
  /**
   * Role ID for anonymous users; should match the 'role' entity ID.
   */
  const ANONYMOUS_ID = AccountInterface::ANONYMOUS_ROLE;
  
  /**
   * Role ID for authenticated users; should match the 'role' entity ID.
   */
  const AUTHENTICATED_ID = AccountInterface::AUTHENTICATED_ROLE;
  
  /**
   * Returns a list of permissions assigned to the role.
   *
   * @return array
   *   The permissions assigned to the role.
   */
  public function getPermissions();
  
  /**
   * Checks if the role has a permission.
   *
   * @param string $permission
   *   The permission to check for.
   *
   * @return bool
   *   TRUE if the role has the permission, FALSE if not.
   */
  public function hasPermission($permission);
  
  /**
   * Grant permissions to the role.
   *
   * @param string $permission
   *   The permission to grant.
   *
   * @return $this
   */
  public function grantPermission($permission);
  
  /**
   * Revokes a permissions from the user role.
   *
   * @param string $permission
   *   The permission to revoke.
   *
   * @return $this
   */
  public function revokePermission($permission);
  
  /**
   * Indicates that a role has all available permissions.
   *
   * @return bool
   *   TRUE if the role has all permissions.
   */
  public function isAdmin();
  
  /**
   * Sets the role to be an admin role.
   *
   * @param bool $is_admin
   *   TRUE if the role should be an admin role.
   *
   * @return $this
   */
  public function setIsAdmin($is_admin);
  
  /**
   * Returns the weight.
   *
   * @return int
   *   The weight of this role.
   */
  public function getWeight();
  
  /**
   * Sets the weight to the given value.
   *
   * @param int $weight
   *   The desired weight.
   *
   * @return $this
   */
  public function setWeight($weight);

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.