RoleInterface.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Drupal\user;
  3. use Drupal\Core\Config\Entity\ConfigEntityInterface;
  4. use Drupal\Core\Session\AccountInterface;
  5. /**
  6. * Provides an interface defining a user role entity.
  7. *
  8. * @ingroup user_api
  9. */
  10. interface RoleInterface extends ConfigEntityInterface {
  11. /**
  12. * Role ID for anonymous users; should match the 'role' entity ID.
  13. */
  14. const ANONYMOUS_ID = AccountInterface::ANONYMOUS_ROLE;
  15. /**
  16. * Role ID for authenticated users; should match the 'role' entity ID.
  17. */
  18. const AUTHENTICATED_ID = AccountInterface::AUTHENTICATED_ROLE;
  19. /**
  20. * Returns a list of permissions assigned to the role.
  21. *
  22. * @return array
  23. * The permissions assigned to the role.
  24. */
  25. public function getPermissions();
  26. /**
  27. * Checks if the role has a permission.
  28. *
  29. * @param string $permission
  30. * The permission to check for.
  31. *
  32. * @return bool
  33. * TRUE if the role has the permission, FALSE if not.
  34. */
  35. public function hasPermission($permission);
  36. /**
  37. * Grant permissions to the role.
  38. *
  39. * @param string $permission
  40. * The permission to grant.
  41. *
  42. * @return $this
  43. */
  44. public function grantPermission($permission);
  45. /**
  46. * Revokes a permissions from the user role.
  47. *
  48. * @param string $permission
  49. * The permission to revoke.
  50. *
  51. * @return $this
  52. */
  53. public function revokePermission($permission);
  54. /**
  55. * Indicates that a role has all available permissions.
  56. *
  57. * @return bool
  58. * TRUE if the role has all permissions.
  59. */
  60. public function isAdmin();
  61. /**
  62. * Sets the role to be an admin role.
  63. *
  64. * @param bool $is_admin
  65. * TRUE if the role should be an admin role.
  66. *
  67. * @return $this
  68. */
  69. public function setIsAdmin($is_admin);
  70. /**
  71. * Returns the weight.
  72. *
  73. * @return int
  74. * The weight of this role.
  75. */
  76. public function getWeight();
  77. /**
  78. * Sets the weight to the given value.
  79. *
  80. * @param int $weight
  81. * The desired weight.
  82. *
  83. * @return $this
  84. */
  85. public function setWeight($weight);
  86. }