function force_password_change_install in Force Password Change 2.0.x
Same name and namespace in other branches
- 8 force_password_change.install \force_password_change_install()
- 6.3 force_password_change.install \force_password_change_install()
- 6.2 force_password_change.install \force_password_change_install()
- 7.2 force_password_change.install \force_password_change_install()
- 7 force_password_change.install \force_password_change_install()
Implements hook_install().
File
- ./
force_password_change.install, line 13
Code
function force_password_change_install() {
$connection = \Drupal::database();
// Create a row for each role in the {force_password_change_roles} table.
$query = $connection
->insert('force_password_change_roles')
->fields([
'rid',
]);
$roles = Role::loadMultiple();
unset($roles[RoleInterface::ANONYMOUS_ID]);
$rids = array_keys($roles);
foreach ($rids as $rid) {
$query
->values([
$rid,
]);
}
$query
->execute();
// Set a variable indicating the module installation date.
// This is used in hook_user() to compare the users signup date with the
// module installation date to see if they were required to change their
// password upon first time login.
// Users who signed up before this variable was set will of course not have
// been required to change their password upon first time login.
$request_time = \Drupal::time()
->getRequestTime();
\Drupal::configFactory()
->getEditable('force_password_change.settings')
->set('installation_date', $request_time)
->save();
}