diff --git a/config/install/field.field.user.user.field_last_password_reset.yml b/config/install/field.field.user.user.field_last_password_reset.yml index 255b485..5306ea8 100644 --- a/config/install/field.field.user.user.field_last_password_reset.yml +++ b/config/install/field.field.user.user.field_last_password_reset.yml @@ -5,7 +5,10 @@ dependencies: - field.storage.user.field_last_password_reset module: - datetime - - password_policy + - user + enforced: + module: + - password_policy id: user.user.field_last_password_reset field_name: field_last_password_reset entity_type: user diff --git a/config/install/field.field.user.user.field_password_expiration.yml b/config/install/field.field.user.user.field_password_expiration.yml index c045b5c..dc538b0 100644 --- a/config/install/field.field.user.user.field_password_expiration.yml +++ b/config/install/field.field.user.user.field_password_expiration.yml @@ -4,7 +4,10 @@ dependencies: config: - field.storage.user.field_password_expiration module: - - password_policy + - user + enforced: + module: + - password_policy id: user.user.field_password_expiration field_name: field_password_expiration entity_type: user @@ -20,4 +23,4 @@ default_value_callback: '' settings: on_label: 'Expired Password' off_label: 'Non-expired Password' -field_type: boolean \ No newline at end of file +field_type: boolean diff --git a/config/install/field.storage.user.field_last_password_reset.yml b/config/install/field.storage.user.field_last_password_reset.yml index 799b887..7909183 100644 --- a/config/install/field.storage.user.field_last_password_reset.yml +++ b/config/install/field.storage.user.field_last_password_reset.yml @@ -4,7 +4,9 @@ dependencies: module: - datetime - user - - password_policy + enforced: + module: + - password_policy id: user.field_last_password_reset field_name: field_last_password_reset entity_type: user @@ -12,8 +14,9 @@ type: datetime settings: datetime_type: datetime module: datetime -locked: false +locked: true cardinality: 1 translatable: true indexes: { } -persist_with_no_fields: false \ No newline at end of file +persist_with_no_fields: false +custom_storage: false diff --git a/config/install/field.storage.user.field_password_expiration.yml b/config/install/field.storage.user.field_password_expiration.yml index 827fb0b..8c4e684 100644 --- a/config/install/field.storage.user.field_password_expiration.yml +++ b/config/install/field.storage.user.field_password_expiration.yml @@ -3,15 +3,18 @@ status: true dependencies: module: - user - - password_policy + enforced: + module: + - password_policy id: user.field_password_expiration field_name: field_password_expiration entity_type: user type: boolean settings: { } module: core -locked: false +locked: true cardinality: 1 translatable: true indexes: { } -persist_with_no_fields: false \ No newline at end of file +persist_with_no_fields: false +custom_storage: false diff --git a/password_policy.install b/password_policy.install index 6439f1b..c683785 100644 --- a/password_policy.install +++ b/password_policy.install @@ -1,54 +1,49 @@ getStorage('user')->loadMultiple(); - $date = date('Y-m-d\TH:i:s'); + // Set user password reset timestamp to now. + $timestamp = gmdate(DATETIME_DATETIME_STORAGE_FORMAT, REQUEST_TIME); + /** @var \Drupal\user\UserInterface[] $users */ + $users = \Drupal::entityTypeManager()->getStorage('user')->loadMultiple(); + // @todo Get rid of updating all users. foreach ($users as $user) { - $user->set('field_last_password_reset', $date); - $user->set('field_password_expiration', '0'); - $user->save(); + $user + ->set('field_last_password_reset', $timestamp) + ->set('field_password_expiration', '0') + ->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(); - -} \ No newline at end of file + // Rebuild user entity form display for new fields. + $storage = \Drupal::entityTypeManager()->getStorage('entity_form_display'); + /** @var $user_form_display \Drupal\Core\Entity\Display\EntityFormDisplayInterface */ + $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(); +} diff --git a/password_policy_length/src/Plugin/PasswordConstraint/PasswordLength.php b/password_policy_length/src/Plugin/PasswordConstraint/PasswordLength.php index 6f93738..59040b9 100644 --- a/password_policy_length/src/Plugin/PasswordConstraint/PasswordLength.php +++ b/password_policy_length/src/Plugin/PasswordConstraint/PasswordLength.php @@ -33,12 +33,12 @@ function validate($password, $user_context) { switch($configuration['character_operation']) { case 'minimum': if (strlen($password) < $configuration['character_length']) { - $validation->setErrorMessage($this->t('The length of the password is !count characters and needs to be at least @length characters', ['!count' => strlen($password), '@length' => $configuration['character_length']])); + $validation->setErrorMessage($this->t('The length of the password is @count characters and needs to be at least @length characters', ['@count' => strlen($password), '@length' => $configuration['character_length']])); } break; case 'maximum': if (strlen($password) > $configuration['character_length']) { - $validation->setErrorMessage($this->t('The length of the password is !count characters and can only be at most @length characters', ['!count' => strlen($password), '@length' => $configuration['character_length']])); + $validation->setErrorMessage($this->t('The length of the password is @count characters and can only be at most @length characters', ['@count' => strlen($password), '@length' => $configuration['character_length']])); } break; } diff --git a/src/Wizard/PasswordPolicyWizard.php b/src/Wizard/PasswordPolicyWizard.php index 0286db2..3458c63 100644 --- a/src/Wizard/PasswordPolicyWizard.php +++ b/src/Wizard/PasswordPolicyWizard.php @@ -48,12 +48,9 @@ public function getMachineLabel() { } /** - * Retrieve a list of FormInterface classes by their step key in the wizard. - * - * @return array - * A + * {@inheritdoc} */ - public function getOperations() { + public function getOperations($cached_values) { return [ 'general' => [ 'title' => $this->t('General Info'), @@ -79,4 +76,4 @@ public function getRouteName() { return 'entity.password_policy.wizard.edit'; } -} \ No newline at end of file +}