Problem/Motivation
Drupal 9.5.5 was released on: 15 Mar 2023
https://www.drupal.org/project/drupal/releases/9.5.5
Facing fatal error issues after updating to Drupal 9.5.5
Maybe related to changes after the fix for
Drupal core - Moderately critical - Information disclosure - SA-CORE-2023-003
The language module provides a Language switcher block which can be placed to provide links to quickly switch between different languages.
The URL of unpublished translations may be disclosed. When used in conjunction with a module like Pathauto, this may reveal the title of unpublished content.
The block will not show up in many pages.
Steps to reproduce
Given that the
"Language Switcher Dropdown"module was installed in a Drupal 9.5.5 site
And placed the language drop down block in a region for the default active theme
And the"Basic Page"content type was configured for content translation
And more languages were added to the system
When adding a"Basic Page"node with"English"as the language
And press the"Save"submit button
Then the following Fatal error will show up
[Wed Mar 15 22:31:44.422064 2023] [php:notice] [pid 1169478] [client 10.50.111.41:35104] TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in /var/www/html/test/drupal9/web/modules/contrib/lang_dropdown/src/Plugin/Block/LanguageDropdownBlock.php on line 726 #0 /var/www/html/test/drupal9/web/modules/contrib/lang_dropdown/src/Plugin/Block/LanguageDropdownBlock.php(726): array_keys()\n#1 /var/www/html/test/drupal9/web/core/modules/block/src/BlockViewBuilder.php(171): Drupal\\lang_dropdown\\Plugin\\Block\\LanguageDropdownBlock->build()\n#2 [internal function]: Drupal\\block\\BlockViewBuilder::preRender()\n#3 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array()\n#4 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Render/Renderer.php(788): Drupal\\Core\\Render\\Renderer->doTrustedCallback()\n#5 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Render/Renderer.php(374): Drupal\\Core\\Render\\Renderer->doCallback()\n#6 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Render/Renderer.php(446): Drupal\\Core\\Render\\Renderer->doRender()\n#7 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\\Core\\Render\\Renderer->doRender()\n#8 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Template/TwigExtension.php(479): Drupal\\Core\\Render\\Renderer->render()\n#9 /var/www/html/test/drupal9/web/sites/default/files/php/twig/64121bc4a90c0_page.html.twig_kr1CGZ6aIrcITbJE5nyBk_3x3/XmVwToDgV8S5wwI412DYRjkeq2vBSeWYl9u6GvLh1RA.php(95): Drupal\\Core\\Template\\TwigExtension->escapeFilter()\n#10 /var/www/html/test/drupal9/vendor/twig/twig/src/Template.php(405): __TwigTemplate_2af0607cd6e854321751a147533f8ec2->doDisplay()\n#11 /var/www/html/test/drupal9/vendor/twig/twig/src/Template.php(378): Twig\\Template->displayWithErrorHandling()\n#12 /var/www/html/test/drupal9/vendor/twig/twig/src/Template.php(390): Twig\\Template->display()\n#13 /var/www/html/test/drupal9/web/core/themes/engines/twig/twig.engine(55): Twig\\Template->render()\n#14 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()\n#15 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\\Core\\Theme\\ThemeManager->render()\n#16 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\\Core\\Render\\Renderer->doRender()\n#17 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Template/TwigExtension.php(479): Drupal\\Core\\Render\\Renderer->render()\n#18 /var/www/html/test/drupal9/web/sites/default/files/php/twig/64121bc4a90c0_html.html.twig_RZHek83SVcT8gDF9-bPXVpyoF/ng2jxdLBGZs31G0aMmFM8WRG0Hi4agQu0k0rEwGQVVI.php(93): Drupal\\Core\\Template\\TwigExtension->escapeFilter()\n#19 /var/www/html/test/drupal9/vendor/twig/twig/src/Template.php(405): __TwigTemplate_bc2efd76ab2aceb2ab69f40efb3bdcd7->doDisplay()\n#20 /var/www/html/test/drupal9/vendor/twig/twig/src/Template.php(378): Twig\\Template->displayWithErrorHandling()\n#21 /var/www/html/test/drupal9/vendor/twig/twig/src/Template.php(390): Twig\\Template->display()\n#22 /var/www/html/test/drupal9/web/core/themes/engines/twig/twig.engine(55): Twig\\Template->render()\n#23 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()\n#24 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\\Core\\Theme\\ThemeManager->render()\n#25 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\\Core\\Render\\Renderer->doRender()\n#26 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(162): Drupal\\Core\\Render\\Renderer->render()\n#27 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\\Core\\Render\\MainContent\\HtmlRenderer->Drupal\\Core\\Render\\MainContent\\{closure}()\n#28 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(163): Drupal\\Core\\Render\\Renderer->executeInRenderContext()\n#29 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\\Core\\Render\\MainContent\\HtmlRenderer->renderResponse()\n#30 [internal function]: Drupal\\Core\\EventSubscriber\\MainContentViewSubscriber->onViewRenderArray()\n#31 /var/www/html/test/drupal9/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()\n#32 /var/www/html/test/drupal9/vendor/symfony/http-kernel/HttpKernel.php(174): Drupal\\Component\\EventDispatcher\\ContainerAwareEventDispatcher->dispatch()\n#33 /var/www/html/test/drupal9/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw()\n#34 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\\Component\\HttpKernel\\HttpKernel->handle()\n#35 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\\Core\\StackMiddleware\\Session->handle()\n#36 /var/www/html/test/drupal9/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\\Core\\StackMiddleware\\KernelPreHandle->handle()\n#37 /var/www/html/test/drupal9/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\\page_cache\\StackMiddleware\\PageCache->pass()\n#38 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\\page_cache\\StackMiddleware\\PageCache->handle()\n#39 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle()\n#40 /var/www/html/test/drupal9/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle()\n#41 /var/www/html/test/drupal9/web/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\\StackedHttpKernel->handle()\n#42 /var/www/html/test/drupal9/web/index.php(19): Drupal\\Core\\DrupalKernel->handle()\n#43 {main}, referer: http://localhost/test/drupal9/web/fr/node/add/page
Proposed resolution
Have a check for links for languages
If Languages is not empty
and if Links is not empty too
and if Links is an array
then use the array_keys
Changes in the Drupal core Language Block
$links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRouteMatch(\Drupal::routeMatch()));
https://git.drupalcode.org/project/drupal/-/commit/18bce0cd518975407921b...
Remaining tasks
- File an issue
- Patch/MR
- Test
- Review
- Release
User interface changes
- N/A
API changes
- N/A
Data model changes
- N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | Error IMG.png | 86.73 KB | menu2crak |
| #16 | lang_dropdown-2-0-0--3348277-16.patch | 3.73 KB | rajab natshah |
| #12 | 3348277-12.patch | 3.66 KB | rajab natshah |
Issue fork lang_dropdown-3348277
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
rajab natshahComment #3
rajab natshahComment #4
rajab natshahComment #6
rajab natshahComment #7
rajab natshahComment #9
rajab natshahHaving issues with
Hide if only one language is available
Not having the same old expected behavior.
Comment #10
rajab natshahMaybe related to changes after the fix for
Drupal core - Moderately critical - Information disclosure - SA-CORE-2023-003
The block will not show up in many pages.
Comment #11
rajab natshahIn Drupal core Language Block
$links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRouteMatch(\Drupal::routeMatch()));https://git.drupalcode.org/project/drupal/-/commit/18bce0cd518975407921b...
Comment #12
rajab natshahThis patch for the 8.x-2.x-dev branch
Comment #13
rajab natshahComment #14
rajab natshahComment #15
rajab natshahComment #16
rajab natshahAttached a patch fix for the
8.x-2.0released tagIt will fail to apply to the DEV branch. ( only use for the tag release )
The patch from #12 will apply to
2.x-devComment #17
nsciacca+1 for the patch in #16, thanks!
Comment #18
prashant.cPatch fails to apply on
Drupal 9.5and module version8.x-2.xerror: patch failed: src/Plugin/Block/LanguageDropdownBlock.php:714Comment #19
prashant.cI personally experienced this error with only logged-in users. The root cause is the change record mentioned at https://www.drupal.org/node/3247792. To resolve this issue, one possible solution is to cast the
<?php array_keys((array)$languages->links) ?>to an array.Comment #20
rajab natshah8.x-2.x8.x-2.0Comment #22
rajab natshahComment #23
rajab natshahComment #24
menu2crak commentedHello, after applying patch 16, I solved the error "TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in Language Drop down Block class" the problem that now gives me another error new. The error occurs because you are trying to count a null variable. Line 239 web/modules/contrib/dropdown_language/src/Plugin/Block/DropdownLanguage.php
Do I have to make a new patch?
Greetings and thank you
Comment #25
bramvandenbulcke commentedThanks for the quick fix Rajab!
Comment #26
prashant.c@menu2crak
No, you do not have to make a new patch. The patch is already there and committed. Regarding contributing to Drupal you can go through the documents
https://www.drupal.org/community/contributor-guide/contribution-areas
https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa...
Comment #28
londova commentedIs there any plan to issue a new module version with this patch included?
Comment #29
laurent222 commentedThanks Rajab for your patch
Comment #30
carma03 commentedConfirming patch #16 worked for 8.x-2.0 on Drupal 9.5.8 and PHP 8.1.
Thanks @rajab-natshah !
Comment #31
CedricCrettaz commentedWhen do you expect to release a new module version correcting this error?
Comment #32
chkavak commentedHello.
Thanks for your answer @Rajab Natshah. I had this problem in Drupal version 9.5.5 and your solution solved the problem.
Now I'm using Drupal version 9.5.9, after updating to version 9.5.8 and 9.5.9 I get the following error when selecting the language in the LanguageDropdown:
The website encountered an unexpected error. Please try again later.
Error: Call to a member function all() on null in Drupal\lang_dropdown\Form\LanguageDropdownForm->submitForm() (line 347 of /var/www/html/drupal/modules/lang_dropdown/src/Form/LanguageDropdownForm.php)
Please help me, I can't find the solution on the internet
Comment #33
thhafner commentedAgreed with above posters. This issue isn't really fixed until there is an actual release of the module with patch #16 included.
Comment #34
rajab natshahComment #35
rajab natshah✅ Released lang_dropdown-8.x-2.1