public PermissionsHashGenerator::generate(AccountInterface $account)
Cached by role, invalidated whenever permissions change.
Overrides PermissionsHashGeneratorInterface::generate
File
- core/lib/Drupal/Core/Session/PermissionsHashGenerator.php, line 57
Class
- PermissionsHashGenerator
- Generates and caches the permissions hash for a user.
Namespace
Drupal\Core\Session
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | public function generate(AccountInterface $account ) { // User 1 is the super user, and can always access all permissions. Use a // different, unique identifier for the hash. if ( $account ->id() == 1) { return $this ->hash( 'is-super-user' ); } $sorted_roles = $account ->getRoles(); sort( $sorted_roles ); $role_list = implode( ',' , $sorted_roles ); $cid = "user_permissions_hash:$role_list" ; if ( $static_cache = $this -> static ->get( $cid )) { return $static_cache ->data; } else { $tags = Cache::buildTags( 'config:user.role' , $sorted_roles , '.' ); if ( $cache = $this ->cache->get( $cid )) { $permissions_hash = $cache ->data; } else { $permissions_hash = $this ->doGenerate( $sorted_roles ); $this ->cache->set( $cid , $permissions_hash , Cache::PERMANENT, $tags ); } $this -> static ->set( $cid , $permissions_hash , Cache::PERMANENT, $tags ); } return $permissions_hash ; } |
Please login to continue.