public function UserEmailPendingChangeAccess::access in Email confirmer 8
Checks access to the given user's pending email change.
Parameters
\Drupal\user\UserInterface $user: The user whose email address is pending confirmation of change.
\Drupal\Core\Session\AccountInterface $account: The currently logged in account.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
File
- email_confirmer_user/
src/ Access/ UserEmailPendingChangeAccess.php, line 55
Class
- UserEmailPendingChangeAccess
- Access check for user email change operations.
Namespace
Drupal\email_confirmer_user\AccessCode
public function access(UserInterface $user, AccountInterface $account) {
$target_account = $user;
// Anonymous users cannot have any pending email change.
if ($target_account
->isAnonymous()) {
return AccessResult::forbidden();
}
// Email change confirmation has to be enabled.
$module_config = $this->configFactory
->get('email_confirmer_user.settings');
$change_config = $module_config
->get('user_email_change');
if (empty($change_config['enabled'])) {
return AccessResult::forbidden()
->addCacheableDependency($module_config);
}
// The target user must have a pending email change.
if (!($new_email = $this->userData
->get('email_confirmer_user', $user
->id(), 'email_change_new_address'))) {
$access_result = AccessResult::forbidden();
}
else {
// Access to update the target account is required by the current user.
$access_result = $target_account
->access('update', $account, TRUE);
}
return $access_result
->cachePerUser()
->addCacheableDependency($target_account);
}