Undefined array key "name"

Created on 5 July 2023, over 1 year ago
Updated 29 April 2024, 7 months ago

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.

๐Ÿ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

๐Ÿ‡ช๐Ÿ‡ธSpain guardiola86

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @guardiola86
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MariaDB 10.3.22
    last update over 1 year ago
    77 pass
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    78 pass
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.4 & SQLite 3.27
    last update over 1 year ago
    77 pass
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    78 pass
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia indrapatil Bangalore

    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

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia bebalachandra

    Hi @guardiola86, as mentioned by @Indrapatil #2 patch applied successfully and I am unable to reproduce the error which is reported. Things are working as expected. We can move this to RTBC.

  • Status changed to RTBC about 1 year ago
  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    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.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States pheski

    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

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom andrew robinson

    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

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    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.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chetan 11

    chetan 11 โ†’ made their first commit to this issueโ€™s fork.

  • Merge request !48fixed โ†’ (Merged) created by chetan 11
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MariaDB 10.3.22
    last update 12 months ago
    77 pass
  • Status changed to Needs review 12 months ago
  • Pipeline finished with Success
    12 months ago
    Total: 241s
    #56627
  • Status changed to Needs work 12 months ago
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

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

  • First commit to issue fork.
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MariaDB 10.3.22
    last update 12 months ago
    77 pass
  • Status changed to Needs review 12 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia viren18febS

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

  • Pipeline finished with Success
    12 months ago
    #57267
  • Status changed to Needs work 12 months ago
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

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

  • First commit to issue fork.
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MariaDB 10.3.22
    last update 11 months ago
    77 pass
  • Status changed to Needs review 11 months ago
  • Pipeline finished with Success
    11 months ago
    Total: 243s
    #63106
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MariaDB 10.3.22
    last update 11 months ago
    77 pass
  • Pipeline finished with Success
    11 months ago
    Total: 243s
    #63107
  • Status changed to Needs work 7 months ago
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    null needs to be uppercase.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia keshav patel

    Keshav Patel โ†’ made their first commit to this issueโ€™s fork.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 7 months ago
    78 pass
  • Status changed to Needs review 7 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia keshav patel

    Updated as per #21, please review.

  • Pipeline finished with Failed
    7 months ago
    Total: 270s
    #145853
  • Status changed to RTBC 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine rollins

    Changes from #23 look good, it can be merged

  • Pipeline finished with Skipped
    7 months ago
    #147385
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 7 months ago
    78 pass
  • Status changed to Fixed 7 months ago
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    Merged.

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

Production build 0.71.5 2024