Undefined array key "theme_key" in Drupal\switch_page_theme\Theme\PageThemeNegotiator

Created on 14 September 2022, about 2 years ago
Updated 16 January 2023, almost 2 years ago

Problem/Motivation

I get the following PHP warnings when trying to access certain admin pages like the "Revisions" tab. on specific nodes.

Warning: Undefined array key "theme_key" in Drupal\switch_page_theme\Theme\PageThemeNegotiator->applies() (line 135 of modules/contrib/switch_page_theme/src/Theme/PageThemeNegotiator.php).

It appears this was introduced by: #3216203: Theme switch not applied on 403/404 pages .

Stack trace:

Warning: Undefined array key "theme_key" in Drupal\switch_page_theme\Theme\PageThemeNegotiator->applies() (line 135 of modules/contrib/switch_page_theme/src/Theme/PageThemeNegotiator.php).
Drupal\switch_page_theme\Theme\PageThemeNegotiator->applies(Object) (Line: 67)
Drupal\Core\Theme\ThemeNegotiator->determineActiveTheme(Object) (Line: 405)
Drupal\Core\Theme\ThemeManager->initTheme(Object) (Line: 96)
Drupal\Core\Theme\ThemeManager->getActiveTheme() (Line: 133)
Drupal\Core\Theme\ThemeManager->render('username', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 117)
Drupal\entity\Controller\RevisionOverviewController->getRevisionDescription(Object, 1) (Line: 132)
Drupal\entity\Controller\RevisionOverviewController->revisionOverview(Object) (Line: 99)
Drupal\entity\Controller\RevisionOverviewController->revisionOverviewController(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
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: 159)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
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: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

Proposed resolution

Use null coalesce operator to handle cases when the array key may not exist.

From:

        $condition = (
          $this->currentRequestIsNotSystem403() &&
          $this->currentPathConfiguredInRules($value["pages"]) &&
          $this->checkThemeKey($value["theme_key"]) &&
          $this->checkCorrectRoles($value['roles'])
        );

To:

        $condition = (
          $this->currentRequestIsNotSystem403() &&
          $this->currentPathConfiguredInRules($value["pages"] ?? '') &&
          $this->checkThemeKey($value["theme_key"] ?? '') &&
          $this->checkCorrectRoles($value['roles'] ?? [])
        );

Remaining tasks

Write patch.

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇪🇨Ecuador jwilson3

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024