function password_policy_install in Password Policy 8.3
Same name and namespace in other branches
- 5 password_policy.install \password_policy_install()
- 6 password_policy.install \password_policy_install()
- 7.2 password_policy.install \password_policy_install()
- 7 password_policy.install \password_policy_install()
Implements hook_install().
File
- ./
password_policy.install, line 13 - Install, update and uninstall functions for the password_policy module.
Code
function password_policy_install() {
// Give precedence to modules like prlp or simple_pass_reset.
module_set_weight('password_policy', 10);
// Set user password reset timestamp to now.
$timestamp = \Drupal::service("date.formatter")
->format(\Drupal::time()
->getRequestTime(), "custom", DateTimeItemInterface::DATETIME_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE);
\Drupal::state()
->set('password_policy.install_time', $timestamp);
// Rebuild user entity form display for new fields.
$storage = \Drupal::entityTypeManager()
->getStorage('entity_form_display');
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $user_form_display */
$user_form_display = $storage
->load('user.user.default');
if (!$user_form_display) {
$user_form_display = $storage
->create([
'targetEntityType' => 'user',
'bundle' => 'user',
'mode' => 'default',
'status' => TRUE,
]);
}
$user_form_display
->setComponent('field_last_password_reset', [
'type' => 'datetime_default',
// Display before contact standard profile field.
'weight' => 4,
'settings' => [],
])
->setComponent('field_password_expiration', [
'type' => 'boolean_checkbox',
'weight' => 3,
'settings' => [
'display_label' => TRUE,
],
])
->save();
}