This happens a lot of the time with custom resources and I cannot figure out why. Custom permissions return wrong value with currentUser
but returns correct value when loading user by uid. $this->currentUser
is valid and the correct account. What's the issue/cause and resolution?
Example:
Wrong value:
$hasViewPermission = $this->currentUser->hasPermission(
sprintf('view %s categories', $termGroup)
);
/// = false
Correct value
$user = User::load(\Drupal::currentUser()->id());
$hasViewPermission = $user->hasPermission(
sprintf('view %s categories', $termGroup)
);
/// true
Role config
permissions:
...
- 'view EDITORIAL categories'