protected function SimpleFbConnectUserManager::loginDisabledByRole in Simple FB Connect 8.3
Same name and namespace in other branches
- 8.2 src/SimpleFbConnectUserManager.php \Drupal\simple_fb_connect\SimpleFbConnectUserManager::loginDisabledByRole()
Checks if the user has one of the "FB login disabled" roles.
Parameters
\Drupal\user\Entity\User $drupal_user: User object.
Return value
bool True if login is disabled for one of this user's role False if login is not disabled for this user's roles
1 call to SimpleFbConnectUserManager::loginDisabledByRole()
- SimpleFbConnectUserManager::loginUser in src/
SimpleFbConnectUserManager.php - Logs the user in.
File
- src/
SimpleFbConnectUserManager.php, line 395
Class
- SimpleFbConnectUserManager
- Contains all logic that is related to Drupal user management.
Namespace
Drupal\simple_fb_connectCode
protected function loginDisabledByRole(User $drupal_user) {
// Read roles that are blocked from module settings.
$disabled_roles = $this->configFactory
->get('simple_fb_connect.settings')
->get('disabled_roles');
// Filter out allowed roles. Allowed roles have have value "0".
// "0" evaluates to FALSE so second parameter of array_filter is omitted.
$disabled_roles = array_filter($disabled_roles);
// Loop through all roles the user has.
foreach ($drupal_user
->getRoles() as $role) {
// Check if FB login is disabled for this role.
if (array_key_exists($role, $disabled_roles)) {
$this->loggerFactory
->get('simple_fb_connect')
->warning('Facebook login for user @user prevented. Facebook login for role @role is disabled in module settings.', [
'@user' => $drupal_user
->getAccountName(),
'@role' => $role,
]);
return TRUE;
}
}
// FB login is not disabled for any of the user's roles.
return FALSE;
}