Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alt_login
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
alt_login
Commits
b69364e4
Commit
b69364e4
authored
5 months ago
by
Matthew Slater
Browse files
Options
Downloads
Patches
Plain Diff
better calling of logger channel and fixed warning
parent
c60f98ce
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
alt_login.module
+5
-5
5 additions, 5 deletions
alt_login.module
with
5 additions
and
5 deletions
alt_login.module
+
5
−
5
View file @
b69364e4
...
@@ -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."
));
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment