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

small fixes

parent 09b73331
No related branches found
No related tags found
No related merge requests found
<?php
/**
* To get the alias of one plugin for one user do this.
* Could be useful for building export routines.
*/
alt_login_get_alias($user, $plugin_id);
\ No newline at end of file
...@@ -4,3 +4,4 @@ project: alt_login ...@@ -4,3 +4,4 @@ project: alt_login
core_version_requirement: ^9 || ^10 || ^11 core_version_requirement: ^9 || ^10 || ^11
type: module type: module
configure: alt_login.admin configure: alt_login.admin
version: 2.0.5
...@@ -26,7 +26,7 @@ function alt_login_help($route_name, $route_match) { ...@@ -26,7 +26,7 @@ function alt_login_help($route_name, $route_match) {
* @note there's no easy way to dedupe accounts' display names. * @note there's no easy way to dedupe accounts' display names.
*/ */
function alt_login_user_format_name_alter(&$name, AccountInterface $account) { function alt_login_user_format_name_alter(&$name, AccountInterface $account) {
if ($account->isAnonymous() or ($account instanceof UserInterface and $account->isNew())) { if ($account->isAnonymous()) {
// This will be the configured 'anonymous' value // This will be the configured 'anonymous' value
return; return;
} }
...@@ -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($names[$uid])) { if (empty(trim($names[$uid]))) {
$names[$uid] = $account->getAccountName(); $names[$uid] = $account->getAccountName();
} }
} }
...@@ -147,8 +147,10 @@ function alt_login_entity_builder($entity_type_id, $entity, $form, $form_state) ...@@ -147,8 +147,10 @@ function alt_login_entity_builder($entity_type_id, $entity, $form, $form_state)
* the form-level validation. * the form-level validation.
*/ */
function alt_login_login_name_element_validate(&$element, $form_state) { function alt_login_login_name_element_validate(&$element, $form_state) {
$name = alt_login_convert_alias($element['#value']); $alt_name = alt_login_convert_alias($element['#value']);
$form_state->setValue('name', $name); if (trim($alt_name)) {
$form_state->setValue('name', $name);
}
} }
/** /**
...@@ -203,9 +205,13 @@ function alt_login_get_aliases(UserInterface $user) { ...@@ -203,9 +205,13 @@ function alt_login_get_aliases(UserInterface $user) {
* Replace the username with any aliases. * Replace the username with any aliases.
*/ */
function alt_login_tokens_alter(&$replacements, array $context, $bubbleable_metadata) { function alt_login_tokens_alter(&$replacements, array $context, $bubbleable_metadata) {
// For some reason the token module, if installed changes the $context
if ($context['type'] == 'user' and isset($context['data']['user']) and isset($replacements['[user:name]'])) { if ($context['type'] == 'user' and isset($context['data']['user']) 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']));
} }
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']));
}
} }
/** /**
......
...@@ -2,4 +2,5 @@ display: '' ...@@ -2,4 +2,5 @@ display: ''
display_anon: 'Member [user:uid]' display_anon: 'Member [user:uid]'
aliases: aliases:
- username - username
name_mode: alt_login_generate_from_address
login: { }
...@@ -15,3 +15,9 @@ alt_login.settings: ...@@ -15,3 +15,9 @@ alt_login.settings:
sequence: sequence:
- type: string - type: string
label: Login option label: Login option
name_mode:
type: string
label: Name mode
login:
type: sequence
label: Login options
...@@ -121,10 +121,10 @@ class AddressName implements AltLoginMethodInterface, ContainerFactoryPluginInte ...@@ -121,10 +121,10 @@ class AddressName implements AltLoginMethodInterface, ContainerFactoryPluginInte
*/ */
function getAlias(UserInterface $user) : string { function getAlias(UserInterface $user) : string {
$field_name = $this->fieldName(); $field_name = $this->fieldName();
return implode(' ', [$user->{$field_name}->given_name, $user->{$field_name}->family_name]); $parts = array_filter([$user->{$field_name}->given_name, $user->{$field_name}->family_name]);
return implode(' ', $parts);
} }
/** /**
* Helper * Helper
* *
......
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