function tfa_update_8003 in Two-factor Authentication (TFA) 8
Move old 'require tfa' permissions into tfa.settings.
File
- ./
tfa.install, line 61 - Installation related functions for TFA module.
Code
function tfa_update_8003() {
$required_roles = [];
$role_storage = \Drupal::entityTypeManager()
->getStorage('user_role');
foreach ($role_storage
->loadMultiple() as $role) {
/** @var \Drupal\user\RoleInterface $role */
$rid = $role
->id();
$required_roles[$rid] = 0;
if ($role
->hasPermission('require tfa')) {
$required_roles[$rid] = $rid;
$role
->revokePermission('require tfa')
->save();
}
}
unset($required_roles[AccountInterface::ANONYMOUS_ROLE]);
$config = \Drupal::configFactory()
->getEditable('tfa.settings');
$config
->set('required_roles', $required_roles)
->save();
}