function Role::hasPermission

Same name and namespace in other branches
  1. 9 core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::hasPermission()
  2. 8.9.x core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::hasPermission()
  3. 11.x core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::hasPermission()

Checks if the role has a permission.

Parameters

string $permission: The permission to check for.

Return value

bool TRUE if the role has the permission, FALSE if not.

Overrides RoleInterface::hasPermission

1 call to Role::hasPermission()
Role::grantPermission in core/modules/user/src/Entity/Role.php
Grant permissions to the role.

File

core/modules/user/src/Entity/Role.php, line 121

Class

Role
Defines the user role entity class.

Namespace

Drupal\user\Entity

Code

public function hasPermission($permission) {
    if ($this->isAdmin()) {
        return TRUE;
    }
    return in_array($permission, $this->permissions);
}

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