-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpassword_policy.install
54 lines (43 loc) · 1.69 KB
/
password_policy.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
use Drupal\field\Entity\FieldStorageConfig;
/**
* Implements hook_install().
*/
function password_policy_install() {
//set user password reset timestamp to now
$users = \Drupal::entityManager()->getStorage('user')->loadMultiple();
$date = date('Y-m-d\TH:i:s');
foreach ($users as $user) {
$user->set('field_last_password_reset', $date);
$user->set('field_password_expiration', '0');
$user->save();
}
//rebuild user entity form display for new fields.
$config = \Drupal::service('config.factory')->getEditable('core.entity_form_display.user.user.default');
// Not sure why this isn't set, but it throws an error in simpletest.
$config->set('targetEntityType', 'user');
$config->set('bundle', 'user');
$dep_module = $config->get('dependencies.module');
$dep_module[] = 'field.field.user.user.field_last_password_reset';
$dep_module[] = 'field.field.user.user.field_password_expiration';
$config->set('dependencies.module', $dep_module);
$dep_config = $config->get('dependencies.config');
$dep_config[] = 'field.field.user.user.field_last_password_reset';
$dep_config[] = 'field.field.user.user.field_password_expiration';
$config->set('dependencies.config', $dep_config);
$last_password_reset = [
'type' => 'datetime_default',
'weight' => '6',
'settings' => [],
'third_party_settings' => [],
];
$config->set('content.field_last_password_reset', $last_password_reset);
$field_password_expiration = [
'type' => 'boolean_checkbox',
'weight' => '5',
'settings' => ['display_label' => 'true'],
'third_party_settings' => [],
];
$config->set('content.field_password_expiration', $field_password_expiration);
$config->save();
}