Deprecated function: mb_strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\Html::getId() (line 219 of core/lib/Drupal/Component/Utility/Html.php)

Created on 12 December 2022, over 2 years ago
Updated 11 July 2024, 9 months ago

Problem/Motivation

For PHP 8.1, calling the mb_strtolower() function with a null argument returns a deprecation error:

Deprecated function: mb_strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\Html::getId() (line 219 of core/lib/Drupal/Component/Utility/Html.php).
Drupal\Component\Utility\Html::getId(NULL) (Line: 121)
__TwigTemplate_fdec0ba362e0f13a146c27640b999ff1->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/citizen_patterns/templates/zzz-custom/widgets/00-base/field--node--field-paragraphs.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('field', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 122)
__TwigTemplate_225f1ad20ce32204822f192356151c59->block_content(Array, Array) (Line: 182)
Twig\Template->displayBlock('content', Array, Array) (Line: 111)
__TwigTemplate_225f1ad20ce32204822f192356151c59->block_blockContent(Array, Array) (Line: 182)
Twig\Template->displayBlock('blockContent', Array, Array) (Line: 78)
__TwigTemplate_225f1ad20ce32204822f192356151c59->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/citizen_patterns/templates/zzz-custom/blocks/block--field-block.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('block', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 97)
__TwigTemplate_1259748214d9a4428585fb011ef8998c->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/citizen_patterns/templates/zzz-custom/layout/layout--twocol-quad-split.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('layout__twocol_quad_split', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 221)
__TwigTemplate_8e8ddbeacf22bec82b0db581af4be584->block_layoutSectionContent(Array, Array) (Line: 182)
Twig\Template->displayBlock('layoutSectionContent', Array, Array) (Line: 194)
__TwigTemplate_8e8ddbeacf22bec82b0db581af4be584->block_layoutSections(Array, Array) (Line: 182)
Twig\Template->displayBlock('layoutSections', Array, Array) (Line: 154)
__TwigTemplate_8e8ddbeacf22bec82b0db581af4be584->block_node(Array, Array) (Line: 182)
Twig\Template->displayBlock('node', Array, Array) (Line: 58)
__TwigTemplate_045d80dce83336544d39f3d671ded776->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array, Array) (Line: 53)
__TwigTemplate_8e8ddbeacf22bec82b0db581af4be584->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/citizen_patterns/templates/zzz-custom/content/node.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
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

I'm not sure I can describe how to reproduce this error reliably but it seems to be related to the use of paragraphs. On the site I'm working on, if the page does not have a paragraph reference, no errors display. The error only shows on pages with paragraphs. Regardless of the cause, the variable needs to checked for a value prior to running any string functions on it.

Proposed resolution

Adding this snippet to line 219 of the web/core/lib/Drupal/Component/Utility/Html.php appears to remedy the problem:

  if (!$id) {
    return;
  }

or converting the code on line 219 to a ternary statement appears to work as well:

  $id = $id ? istr_replace([' ', '_', '[', ']'], ['-', '-', '-', ''], mb_strtolower($id)) : '';

Remaining tasks

Complete tasks from #11
Ensure all work identified by tags is complete
Hide all patches, we are using only MRs now.

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Render 

Last updated 1 day ago

Created by

🇺🇸United States jumpsuitgreen

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

Production build 0.71.5 2024