comparison core/modules/user/user.module @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
489 // Set the name to a formatted name that is safe for printing and 489 // Set the name to a formatted name that is safe for printing and
490 // that won't break tables by being too long. Keep an unshortened, 490 // that won't break tables by being too long. Keep an unshortened,
491 // unsanitized version, in case other preprocess functions want to implement 491 // unsanitized version, in case other preprocess functions want to implement
492 // their own shortening logic or add markup. If they do so, they must ensure 492 // their own shortening logic or add markup. If they do so, they must ensure
493 // that $variables['name'] is safe for printing. 493 // that $variables['name'] is safe for printing.
494 $name = $account->getDisplayName(); 494 $name = $account->getDisplayName();
495 $variables['name_raw'] = $account->getUsername(); 495 $variables['name_raw'] = $account->getUsername();
496 if (Unicode::strlen($name) > 20) { 496 if (mb_strlen($name) > 20) {
497 $name = Unicode::truncate($name, 15, FALSE, TRUE); 497 $name = Unicode::truncate($name, 15, FALSE, TRUE);
498 $variables['truncated'] = TRUE; 498 $variables['truncated'] = TRUE;
499 } 499 }
500 else { 500 else {
501 $variables['truncated'] = FALSE; 501 $variables['truncated'] = FALSE;
567 } 567 }
568 568
569 /** 569 /**
570 * Implements hook_user_login(). 570 * Implements hook_user_login().
571 */ 571 */
572 function user_user_login($account) { 572 function user_user_login(UserInterface $account) {
573 // Reset static cache of default variables in template_preprocess() to reflect 573 // Reset static cache of default variables in template_preprocess() to reflect
574 // the new user. 574 // the new user.
575 drupal_static_reset('template_preprocess'); 575 drupal_static_reset('template_preprocess');
576 } 576 }
577 577
578 /** 578 /**
579 * Implements hook_user_logout(). 579 * Implements hook_user_logout().
580 */ 580 */
581 function user_user_logout($account) { 581 function user_user_logout(AccountInterface $account) {
582 // Reset static cache of default variables in template_preprocess() to reflect 582 // Reset static cache of default variables in template_preprocess() to reflect
583 // the new user. 583 // the new user.
584 drupal_static_reset('template_preprocess'); 584 drupal_static_reset('template_preprocess');
585 } 585 }
586 586
607 'timestamp' => $timestamp, 607 'timestamp' => $timestamp,
608 'hash' => user_pass_rehash($account, $timestamp), 608 'hash' => user_pass_rehash($account, $timestamp),
609 ], 609 ],
610 [ 610 [
611 'absolute' => TRUE, 611 'absolute' => TRUE,
612 'language' => \Drupal::languageManager()->getLanguage($langcode) 612 'language' => \Drupal::languageManager()->getLanguage($langcode),
613 ] 613 ]
614 ); 614 );
615 } 615 }
616 616
617 /** 617 /**
636 $langcode = isset($options['langcode']) ? $options['langcode'] : $account->getPreferredLangcode(); 636 $langcode = isset($options['langcode']) ? $options['langcode'] : $account->getPreferredLangcode();
637 $url_options = ['absolute' => TRUE, 'language' => \Drupal::languageManager()->getLanguage($langcode)]; 637 $url_options = ['absolute' => TRUE, 'language' => \Drupal::languageManager()->getLanguage($langcode)];
638 return \Drupal::url('user.cancel_confirm', [ 638 return \Drupal::url('user.cancel_confirm', [
639 'user' => $account->id(), 639 'user' => $account->id(),
640 'timestamp' => $timestamp, 640 'timestamp' => $timestamp,
641 'hashed_pass' => user_pass_rehash($account, $timestamp) 641 'hashed_pass' => user_pass_rehash($account, $timestamp),
642 ], $url_options); 642 ], $url_options);
643 } 643 }
644 644
645 /** 645 /**
646 * Creates a unique hash value for use in time-dependent per-user URLs. 646 * Creates a unique hash value for use in time-dependent per-user URLs.
688 */ 688 */
689 function user_cancel($edit, $uid, $method) { 689 function user_cancel($edit, $uid, $method) {
690 $account = User::load($uid); 690 $account = User::load($uid);
691 691
692 if (!$account) { 692 if (!$account) {
693 drupal_set_message(t('The user account %id does not exist.', ['%id' => $uid]), 'error'); 693 \Drupal::messenger()->addError(t('The user account %id does not exist.', ['%id' => $uid]));
694 \Drupal::logger('user')->error('Attempted to cancel non-existing user account: %id.', ['%id' => $uid]); 694 \Drupal::logger('user')->error('Attempted to cancel non-existing user account: %id.', ['%id' => $uid]);
695 return; 695 return;
696 } 696 }
697 697
698 // Initialize batch (to set title). 698 // Initialize batch (to set title).
759 if (!empty($edit['user_cancel_notify'])) { 759 if (!empty($edit['user_cancel_notify'])) {
760 _user_mail_notify('status_blocked', $account); 760 _user_mail_notify('status_blocked', $account);
761 } 761 }
762 $account->block(); 762 $account->block();
763 $account->save(); 763 $account->save();
764 drupal_set_message(t('%name has been disabled.', ['%name' => $account->getDisplayName()])); 764 \Drupal::messenger()->addStatus(t('%name has been disabled.', ['%name' => $account->getDisplayName()]));
765 $logger->notice('Blocked user: %name %email.', ['%name' => $account->getAccountName(), '%email' => '<' . $account->getEmail() . '>']); 765 $logger->notice('Blocked user: %name %email.', ['%name' => $account->getAccountName(), '%email' => '<' . $account->getEmail() . '>']);
766 break; 766 break;
767 767
768 case 'user_cancel_reassign': 768 case 'user_cancel_reassign':
769 case 'user_cancel_delete': 769 case 'user_cancel_delete':
770 // Send account canceled notification if option was checked. 770 // Send account canceled notification if option was checked.
771 if (!empty($edit['user_cancel_notify'])) { 771 if (!empty($edit['user_cancel_notify'])) {
772 _user_mail_notify('status_canceled', $account); 772 _user_mail_notify('status_canceled', $account);
773 } 773 }
774 $account->delete(); 774 $account->delete();
775 drupal_set_message(t('%name has been deleted.', ['%name' => $account->getDisplayName()])); 775 \Drupal::messenger()->addStatus(t('%name has been deleted.', ['%name' => $account->getDisplayName()]));
776 $logger->notice('Deleted user: %name %email.', ['%name' => $account->getAccountName(), '%email' => '<' . $account->getEmail() . '>']); 776 $logger->notice('Deleted user: %name %email.', ['%name' => $account->getAccountName(), '%email' => '<' . $account->getEmail() . '>']);
777 break; 777 break;
778 } 778 }
779 779
780 // After cancelling account, ensure that user is logged out. We can't destroy 780 // After cancelling account, ensure that user is logged out. We can't destroy