function social_user_form_user_form_alter in Open Social 8.2
Same name and namespace in other branches
- 8.9 modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
- 8 modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
- 8.3 modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
- 8.4 modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
- 8.5 modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
- 8.6 modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
- 8.7 modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
- 8.8 modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
- 10.3.x modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
- 10.0.x modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
- 10.1.x modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
- 10.2.x modules/social_features/social_user/social_user.module \social_user_form_user_form_alter()
Implements hook_form_FORM_ID_alter().
See also
File
- modules/
social_features/ social_user/ social_user.module, line 69 - The social user module alterations.
Code
function social_user_form_user_form_alter(&$form, FormStateInterface $form_state) {
// Add forcing of changing password, message to user
// if they logged in via a one-time login link.
// See AccountForm.php this is where user_pass_reset gets set. Only when user
// uses a one time login link it's true.
if ($form_state
->get('user_pass_reset')) {
$form['#attached']['library'][] = 'social_user/user_form_protection';
// We prepend it because a user first has to be saved :) and the profile
// user save needs to fire first!
$form['actions']['submit']['#submit'][] = '_social_user_pass_reset_submit';
// We have to pass some values, because at this point the user is still
// unsaved and the createdTime and the changedTime are still the same!
// So it's actually the first time the user logs in and we can do our
// redirect.
$user = \Drupal::routeMatch()
->getParameter('user');
$storage = \Drupal::entityTypeManager()
->getStorage('profile');
/** @var \Drupal\profile\Entity\ProfileInterface $profile */
$profile = $storage
->loadByUser($user, 'profile');
if (!$profile instanceof ProfileInterface) {
$profile =& $user;
}
if ($profile
->getCreatedTime() == $profile
->getChangedTime()) {
// Remove unwanted message.
$message = 'You have just used your one-time login link. It is no longer necessary to use this link to log in. Please change your password.';
if (isset($_SESSION['messages'])) {
foreach ($_SESSION['messages'] as $type => $messages) {
if ($type == 'status') {
$key = array_search($message, $messages);
if ($key !== FALSE) {
unset($_SESSION['messages'][$type][$key]);
}
}
}
if (empty($_SESSION['messages']['status'])) {
unset($_SESSION['messages']['status']);
}
}
$form_state
->set('first_time_login', TRUE);
}
}
}