Problem/Motivation
Upgrading PHP version to 8.1 produces fatal errors on language detection and selection admin form. These issues were shown as warnings on previous PHP versions. (/admin/config/regional/language/detection)
Error trace:
The website encountered an unexpected error. Please try again later.
TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in in_array() (line 138 of core/modules/language/src/Form/NegotiationConfigureForm.php).
in_array('language_interface', NULL) (Line: 138)
Drupal\language\Form\NegotiationConfigureForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 534)
Drupal\Core\Form\FormBuilder->retrieveForm('language_negotiation_configure_form', Object) (Line: 281)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
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: 169)
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: 265)
Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 132)
Drupal\shield\ShieldMiddleware->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: 713)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)Steps to reproduce
- Install core version 9.5.3 using PHP version 8.1.5
- Visit
/admin/config/regional/language/detection
Proposed resolution
Update code to remove errors.
Comments
Comment #2
hebl commentedComment #3
hebl commentedComment #4
cilefen commentedDrupal core doesn’t have a shield module so the steps to reproduce cannot be accurate.
Comment #5
sourav_paul@cilefen I also facing the same issue...
Comment #6
maxstarkenburgI'm reproducing this error by visiting
/admin/config/regional/language/detectionon a D10.0.11 (php 8.1.17) site that doesn't useshield. Here's what I'm seeing instead:However, I tried to reproduce on different site (9.5.11, php 8.1.24) and couldn't reproduce there (page seemed to load fine, and no dblog warnings). Haven't done a full dig into what other site differences might explain the error on the former vs. lack thereof on the latter.
Comment #7
cybercoda commentedStatus report shows "The Content Language Settings entity type needs to be installed." after upgrade from Drupal 8 to Drupal 9. Tried upgrading from Drupal 9 to Drupal 10 but still have the "The Content Language Settings entity type needs to be installed.". Went I try to visit "/admin/config/regional/language" or "/admin/config/regional/language/detection" on either site to set content language I get "The website encountered an unexpected error. Please try again later.". Watchdog shows the following error...
TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in in_array() (line 137 of /var/www/html/web/core/modules/language/src/Form/NegotiationConfigureForm.php)
#0 /var/www/html/web/core/modules/language/src/Form/NegotiationConfigureForm.php(137): in_array('language_interf...', NULL)
#1 [internal function]: Drupal\language\Form\NegotiationConfigureForm->buildForm(Array, Object(Drupal\Core\Form\FormState))
#2 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array(Array, Array)
#3 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(283): Drupal\Core\Form\FormBuilder->retrieveForm('language_negoti...', Object(Drupal\Core\Form\FormState))
#4 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\language\Form\NegotiationConfigureForm), Object(Drupal\Core\Form\FormState))
#5 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#6 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#7 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#8 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#9 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#10 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#11 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#12 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#13 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#21 {main}
Comment #9
quietone commentedIs this error preventing any site from upgrading to a supported version of Drupal?
If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core")
If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #10
acbramley commentedDoesn't appear to be any steps to reproduce from the latest version of core. Closing as per above.
Comment #11
bbox1 commentedOne of our devs encountered this. I can't say for sure how to recreate, but disabling and re-enabling the language module fixed our use case on a Drupal 10.5.1 site.
Best of luck!