Skip to content
Snippets Groups Projects
Commit b69364e4 authored by Matthew Slater's avatar Matthew Slater
Browse files

better calling of logger channel and fixed warning

parent c60f98ce
No related branches found
No related tags found
No related merge requests found
...@@ -49,7 +49,7 @@ function alt_login_user_format_name_alter(&$name, AccountInterface $account) { ...@@ -49,7 +49,7 @@ function alt_login_user_format_name_alter(&$name, AccountInterface $account) {
); );
} }
// If the above didn't produce a string, fall back to the username. // If the above didn't produce a string, fall back to the username.
if (empty(trim($names[$uid]))) { if (!isset($names[$uid]) or empty(trim($names[$uid]))) {
$names[$uid] = $account->getAccountName(); $names[$uid] = $account->getAccountName();
} }
} }
...@@ -212,6 +212,7 @@ function alt_login_tokens_alter(&$replacements, array $context, $bubbleable_meta ...@@ -212,6 +212,7 @@ function alt_login_tokens_alter(&$replacements, array $context, $bubbleable_meta
if ($context['type'] == 'entity' and isset($context['data']['entity']) and isset($replacements['[user:name]'])) { if ($context['type'] == 'entity' and isset($context['data']['entity']) and isset($replacements['[user:name]'])) {
$replacements['[user:name]'] = implode(t(' OR '), alt_login_get_aliases($context['data']['user'])); $replacements['[user:name]'] = implode(t(' OR '), alt_login_get_aliases($context['data']['user']));
} }
//\Drupal::entityQuery('user')->condition('name', "$new_name%", 'LIKE')->accessCheck(FALSE)->execute();
} }
/** /**
...@@ -229,7 +230,6 @@ function alt_login_user_presave(UserInterface $account) { ...@@ -229,7 +230,6 @@ function alt_login_user_presave(UserInterface $account) {
$login_aliases = \Drupal::Config('alt_login.settings')->get('aliases'); $login_aliases = \Drupal::Config('alt_login.settings')->get('aliases');
if (!in_array('username', $login_aliases)) { if (!in_array('username', $login_aliases)) {
$new_name = substr($account->getEmail(), 0, strpos($account->getEmail(), '@')); $new_name = substr($account->getEmail(), 0, strpos($account->getEmail(), '@'));
//\Drupal::entityQuery('user')->condition('name', "$new_name%", 'LIKE')->accessCheck(FALSE)->execute();
$lastname = \Drupal::database()->select('users_field_data', 'u') $lastname = \Drupal::database()->select('users_field_data', 'u')
->fields('u', ['name']) ->fields('u', ['name'])
->condition('name', "$new_name%", 'LIKE') ->condition('name', "$new_name%", 'LIKE')
...@@ -245,7 +245,7 @@ function alt_login_user_presave(UserInterface $account) { ...@@ -245,7 +245,7 @@ function alt_login_user_presave(UserInterface $account) {
} }
$account->setUsername($new_name); $account->setUsername($new_name);
// Note that the the User RegisterForm logs user creation with another name. // Note that the the User RegisterForm logs user creation with another name.
\Drupal::logger('alt_login')->notice('New user name set to '.$new_name); \Drupal::service('logger.channel.alt_login')->notice('New user name set to '.$new_name);
} }
// Construct the user->name from the address given and last names // Construct the user->name from the address given and last names
...@@ -253,12 +253,12 @@ function alt_login_user_presave(UserInterface $account) { ...@@ -253,12 +253,12 @@ function alt_login_user_presave(UserInterface $account) {
if (empty($login_aliases['username']) and $login_aliases['address_name'] and $address = $account->address->getValue()) { if (empty($login_aliases['username']) and $login_aliases['address_name'] and $address = $account->address->getValue()) {
$givenname = isset($address[0]['given_name']) ? trim($address[0]['given_name']) : ''; $givenname = isset($address[0]['given_name']) ? trim($address[0]['given_name']) : '';
$familyname = isset($address[0]['family_name']) ? trim($address[0]['family_name']) : ''; $familyname = isset($address[0]['family_name']) ? trim($address[0]['family_name']) : '';
$name = trim("$givenname .' '.$familyname"); $name = trim($givenname .' '. $familyname);
if ($name) { if ($name) {
$account->setUsername($name); $account->setUsername($name);
} }
else { else {
\Drupal::logger('alt_login')->error(t("Address name is required to set username.")); \Drupal::service('logger.channel.alt_login')->error(t("Address name is required to set username."));
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment