Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
My patterns (tokens) were not being honored and no matter what patterns or configuration options I tried the generated user name was always a random string. Upon troubleshooting I found that the call to load the pattern from configuration was always empty/blank.
I've created a patch that changes the way the pattern is loaded and this solves the issue as the pattern is now loaded and the names automatically generated as expected.
Comment | File | Size | Author |
---|---|---|---|
#17 | 2904513-17-auto_username-fix-to-load-config.patch | 3.78 KB | dkosbob |
Comments
Comment #2
3CWebDev CreditAttribution: 3CWebDev commentedComment #3
johan.gant CreditAttribution: johan.gant at Deeson commentedNot totally sure about conventions here, but I struggled to have quantumized's patch apply alongside another, useful one: https://www.drupal.org/node/2918391 due to differences in patch formats.
If I reapply the patch above against 8.x-1.x with `git format-patch` then they both apply cleanly. I've uploaded the output to here, but it probably shouldn't be credited to me if it's committed into the next release.
Comment #4
superbole CreditAttribution: superbole commentedThank you very much!
This patch solved my problem!
Comment #5
wturrell CreditAttribution: wturrell commentedWith either patch, the username is correctly set, but I get the following error:
autoUsernameCleanTokenValues() seems to be expecting an array but according to the stack trace is being passed the raw value of
auto_username.setting.aun_pattern
- "[user:mail]" - as a string… am I missing something obvious?(core 8.5.5, php 7.1.18)
Comment #6
wturrell CreditAttribution: wturrell commented[incorrect stuff removed]
Comment #7
wturrell CreditAttribution: wturrell commentedEDIT Completely misunderstood this, sorry. I misread #3 as suggesting the patches had been combined.
#2918391: Incorrect callback given to token replacement in autoUsernamePatternprocessor fixes the warning in autoUsernameCleanTokenValues() I mentioned in #5 (that error didn't show up immediately for me, hence my confusion.)
TL;DR: if you're using composer, you could do this:
Comment #8
wturrell CreditAttribution: wturrell commented(Hide useless patch, add callback as related issue, fix typo in issue title)
Comment #9
andrezstar CreditAttribution: andrezstar commented#8 works fine
Comment #10
AaronBaumanEdit: This change is unncessary and unrelated, given the fix in #2918391
Comment #11
AaronBaumanPatch #3 is good to go.
Comment #12
AaronBaumanComment #13
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedPatch in #3 works well, but there is a warning when applying the patch:
git apply 2904513-fix-to-load-pattern-config-with-author-info.patch
2904513-fix-to-load-pattern-config-with-author-info.patch:22: trailing whitespace.
warning: 1 line adds whitespace errors.
Comment #14
AaronBaumanComment #15
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedThank you, #14 works well.
Comment #16
lazyD CreditAttribution: lazyD commentedfor me tokens were not getting loaded... did below and it worked for me... Hope this helps someone....
FileName -> AutoUsernameSettingsForm.php
Function -> autoUsernamePatternprocessor
- $pattern = \Drupal::state()->get('aun_pattern', ''); -> Remove this line
+ $pattern = \Drupal::config('auto_username.settings')->get('aun_pattern'); ->Add this line
Cheers.
Comment #17
dkosbob CreditAttribution: dkosbob at Message Agency commentedYeah, config wasn't getting loaded for anything. This patch expands on the patch from #14 to include the rest of the config calls.
Comment #18
dkosbob CreditAttribution: dkosbob at Message Agency commentedComment #19
GaëlGThe last patch in #2895214: Misuse the State API fixed the problem for me. Several problems, same cause?
Comment #20
thomasmurphy CreditAttribution: thomasmurphy at Xequals commented#17 worked well for me.
Comment #21
thomasmurphy CreditAttribution: thomasmurphy at Xequals commentedMinor bug still after applying this patch: usernames are being updated on user accounts edits when this functionality is disabled in the module config.
Comment #22
thomasmurphy CreditAttribution: thomasmurphy at Xequals commentedComment #23
jlscott CreditAttribution: jlscott commentedCommitted, with an additional fix for point made by @thomasmurphy.