}
/** @var \Drupal\user\Entity\User $account */
- $account = entity_create('user');
+ $account = \Drupal::entityTypeManager()->getStorage('user')->create();
$account->setUsername($params['cms_name'])->setEmail($params[$mail]);
// Allow user to set password only if they are an admin or if
if ($user_register_conf != 'visitors' && !$user->hasPermission('administer users')) {
$account->block();
}
- elseif (!$verify_mail_conf) {
+ elseif ($verify_mail_conf) {
$account->activate();
}
// Validate the user object
$violations = $account->validate();
if (count($violations)) {
+ foreach ($violations as $violation) {
+ CRM_Core_Session::setStatus($violation->getPropertyPath() . ': ' . $violation->getMessage(), '', 'alert');
+ }
return FALSE;
}
}
// If this is a user creating their own account, login them in!
- if ($account->isActive() && $user->isAnonymous()) {
+ if (!$verify_mail_conf && $account->isActive() && $user->isAnonymous()) {
\user_login_finalize($account);
}
* @inheritDoc
*/
public function updateCMSName($ufID, $email) {
- $user = entity_load('user', $ufID);
+ $user = \Drupal::entityTypeManager()->getStorage('user')->load($ufID);
if ($user && $user->getEmail() != $email) {
$user->setEmail($email);
if (!empty($params['name'])) {
$name = $params['name'];
- $user = entity_create('user');
+ $user = \Drupal::entityTypeManager()->getStorage('user')->create();
$user->setUsername($name);
// This checks for both username uniqueness and validity.
if (!empty($params['mail'])) {
$mail = $params['mail'];
- $user = entity_create('user');
+ $user = \Drupal::entityTypeManager()->getStorage('user')->create();
$user->setEmail($mail);
// This checks for both email uniqueness.
*/
public function getLoginURL($destination = '') {
$query = $destination ? ['destination' => $destination] : [];
- return \Drupal::url('user.login', [], ['query' => $query]);
+ return \Drupal\Core\Url::fromRoute('user.login', [], ['query' => $query])->toString();
}
/**
CRM_Utils_Hook::config($config);
if ($loadUser) {
- if (!empty($params['uid']) && $username = \Drupal\user\Entity\User::load($params['uid'])->getUsername()) {
+ if (!empty($params['uid']) && $username = \Drupal\user\Entity\User::load($params['uid'])->getAccountName()) {
$this->loadUser($username);
}
elseif (!empty($params['name']) && !empty($params['pass']) && \Drupal::service('user.auth')->authenticate($params['name'], $params['pass'])) {