Problem/Motivation
I'm getting this error sometimes:
Warning: Undefined array key "name" in /var/www/html/web/modules/contrib/token/src/Token.php on line 89
Steps to reproduce
It's not easy to reproduce, it happens randomly.
Proposed resolution
Check if name index exists.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | after patch.png | 579.23 KB | bebalachandra |
| #6 | Before patch.png | 754.04 KB | bebalachandra |
| #2 | undefined-array-key-name-3372497-2.patch | 523 bytes | guardiola86 |
Issue fork token-3372497
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
guardiola86 commentedComment #3
guardiola86 commentedComment #4
indrapatil commentedHi @guardiola86
I applied the patch it worked fine and I wasn't able to reproduce the error given.
Let's wait for someone else to review as well.
RTBC + 1
Comment #5
bebalachandra commentedAs mentioned in the issue description I am unable to reproduce the issue on my local. but the way we are handling "name" in line no.89 seems to throw warning sometimes. As I have observed in patch #2, solution for the undefined array key is covered in the patch. So better we need to apply this patch as a better way of writing code and avoid future errors/warnings related to undefined array key. attached before and after patch screenshots for reference.
I suggest to move this ticket to RTBC
Comment #6
bebalachandra commentedComment #7
bebalachandra commentedComment #8
berdirThis would happen with incorrectly defined tokens, just ignoring them will result in weird sorting I think this should be check explicitly somewhere that tokens are correctly defined.
Comment #9
pheski commentedI am not sure if this is the same issue or a separate issue. I upgraded 2 sites from Drupal 9.5.11 to 10.1.6 and got a warning related to Token 1.13:
Warning: Undefined array key “name” in Drupal\token\Token->prepareMultisort() (line 89 of modules/contrib/token/src/Token.php. Here is the full warnibng:
It goes away if I revert to Token 1.12
Comment #10
andrew robinson commentedI found a way to consistently reproduce this error.
- Run `drush cr`
- Open the status report page (/admin/reports/status)
The error message is displayed at the top of the page, but only for the first page request after a cache clear.
I tried applying the patch from comment #2 but this resulted in:
ValueError: Array sizes are inconsistent in array_multisort() (line 64 of modules/contrib/token/src/Token.php).
The solution in my case was to look in custom modules for poorly defined tokens in hook_token_info and fix them by ensuring they all have a 'name' key.
I was able to see a list of custom tokens and any that are missing names by browsing to /admin/help/token
I am running a Drupal 10.1.6 site using Token 1.13
Comment #11
berdirInstead of only conditionally adding the element, the patch should default to an empty string or maybe zzz or something to have those sorted at the end.
We have the requirements check to mention such invalid token definitions, so we don't need any logging, so I'm taking #8 back.
Comment #14
chetan 11 commentedHi,
I have fixed the above error on "token" module, please check the raised MR.
Thanks.
Comment #15
berdirThe MR incorrectly changes indendation, ?? NULL can be used and then there's no need for a local variable.
Comment #17
viren18febs commented@Berdir, I have update the MR with updates, please review.
Comment #18
berdirThere are still some incorrect and unrelated changes on the closing }.
Comment #20
sourabhjainComment #21
berdirnull needs to be uppercase.
Comment #23
keshav patel commentedUpdated as per #21, please review.
Comment #24
rollins commentedChanges from #23 look good, it can be merged
Comment #26
berdirMerged.