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.

Issue fork token-3372497

Command icon 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

guardiola86 created an issue. See original summary.

guardiola86’s picture

StatusFileSize
new523 bytes
guardiola86’s picture

Status: Needs work » Needs review
indrapatil’s picture

Hi @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

bebalachandra’s picture

As 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

bebalachandra’s picture

StatusFileSize
new754.04 KB
new579.23 KB
bebalachandra’s picture

Status: Needs review » Reviewed & tested by the community
berdir’s picture

Status: Reviewed & tested by the community » Needs work

This 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.

pheski’s picture

I 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:

Drupal\token\Token->prepareMultisort(Array) (Line: 60)
Drupal\token\Token->getInfo() (Line: 94)
token_get_token_problems() (Line: 16)
token_requirements('runtime')
call_user_func_array(Object, Array) (Line: 409)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'token') (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('requirements', Object) (Line: 416)
Drupal\Core\Extension\ModuleHandler->invokeAll('requirements', Array) (Line: 109)
Drupal\system\SystemManager->listRequirements() (Line: 53)
Drupal\system\Controller\SystemInfoController->status()
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

It goes away if I revert to Token 1.12

andrew robinson’s picture

I 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

berdir’s picture

Instead 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.

chetan 11 made their first commit to this issue’s fork.

chetan 11’s picture

Status: Needs work » Needs review

Hi,
I have fixed the above error on "token" module, please check the raised MR.
Thanks.

berdir’s picture

Status: Needs review » Needs work

The MR incorrectly changes indendation, ?? NULL can be used and then there's no need for a local variable.

viren18febS made their first commit to this issue’s fork.

viren18febs’s picture

Status: Needs work » Needs review

@Berdir, I have update the MR with updates, please review.

berdir’s picture

Status: Needs review » Needs work

There are still some incorrect and unrelated changes on the closing }.

sourabhjain made their first commit to this issue’s fork.

sourabhjain’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Needs work

null needs to be uppercase.

Keshav Patel made their first commit to this issue’s fork.

keshav patel’s picture

Status: Needs work » Needs review

Updated as per #21, please review.

rollins’s picture

Status: Needs review » Reviewed & tested by the community

Changes from #23 look good, it can be merged

  • Berdir committed 83e4f589 on 8.x-1.x authored by chetan 11
    Issue #3372497 by sourabhjain, chetan 11, guardiola86, Keshav Patel,...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Merged.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.