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

Issue fork drupal-3326684

Command icon 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

jumpsuitgreen created an issue. See original summary.

jumpsuitgreen’s picture

Attached is a proposed patch for this issue.

jumpsuitgreen’s picture

Disregard that last patch.

jumpsuitgreen’s picture

The origin of the problem on the site I worked on was a null value being passed to the clean_id filter in a Twig template. The immediate solution was to test the variable there first and only engage the filter when a value was present.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bmahesh03121 made their first commit to this issue’s fork.

prem suthar’s picture

StatusFileSize
new737 bytes

Resolve The Custom CMD Failed Of Merge.

prem suthar’s picture

StatusFileSize
new721 bytes

Solved the Failed Patch.

prem suthar’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs steps to reproduce, +Needs tests

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

This could use steps to reproduce, to be added to the issue summary.

Though how I see Drupal usually handles these is to figure out what is causing the issue vs treating a symptom.

As a bug it will need a test case.

selvakumar-96’s picture

StatusFileSize
new700 bytes

Deprecated function: mb_strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\system\Plugin\Condition\RequestPath->evaluate() (line 144 of core/modules/system/src/Plugin/Condition/RequestPath.php).

For the above issue check the patch added.

selvakumar-96’s picture

StatusFileSize
new704 bytes
heddn’s picture

I think we should add some logging and not make this too silent. Per #11. But previous to PHP 8.1, this would have silently been eaten, so doing a silent treatment also isn't the worst thing in the world.

mohammad-fayoumi’s picture

StatusFileSize
new1.18 KB

updating the patches and adopting a solution that assigns a default value to the string parameter before invoking mb_strtolower(). This approach ensures compatibility with PHP 8.1 and prevents passing null as the string parameter, which triggers the deprecation warning.

mohammad-fayoumi’s picture

Status: Needs work » Needs review
socialnicheguru’s picture

@Mohammad-Fayoumi is there an interdiff?
nevermind, it is not that big of a patch.

it does apply.

mohammad-fayoumi’s picture

smustgrave’s picture

Status: Needs review » Needs work

Was previously tagged for steps to reproduce and tests which still needs to happen.

Did not review or test.

leo liao’s picture

StatusFileSize
new1.88 KB
connbi’s picture

StatusFileSize
new1.18 KB

New patch for Drupal 10.1.2

abhisekmazumdar’s picture

StatusFileSize
new660 bytes
new1.82 KB

I was trying to do a fresh install for one of the Drupal projects I'm working on, which is on version 10.1.2. I encountered a similar error, but the error originated from a different file.

elc’s picture

The need to guard against value key being empty in core/lib/Drupal/Core/Config/Entity/Query/Condition.php is negated for me by patching with the one line change in #3302838: Querying with NULL values results in warning mb_strtolower(): Passing null to parameter is deprecated. It means that the value passed into the function is not empty instead of the receiving function needing to guard against it.

I have not run into the others as yet.

rcodina’s picture

The patch on the MR (https://git.drupalcode.org/project/drupal/-/merge_requests/3199.patch) fixed the problem for me on Drupal 10.1.6.

On the other hand, notice that not all file patches attached on this issue solve the original error described in issue description. So we need to either focus on the MR or the patch. The patch and/or the MR should include the original getId method fix and include all other reported mb_strtolower issues under PHP 8.1.

rcodina’s picture

Version: 9.5.x-dev » 11.x-dev
sanduhrs’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new2.15 KB

MR !3199 works and looks reasonable to me.

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

I'm triaging RTBC issues. I read the IS and skimmed through the comments.

The work asked for in #11, which is supported by heddn in #14, and asked for again in #19 has not been completed. It is vital that it is know how this can happen on Drupal core, otherwise the root cause will not be fixed by the current change. I am setting this to Needs work.

ikeigenwijs’s picture

We also have this deprecated alert, but we dont use paragraphs on the site.
D10 on php 8.2
Deprecated function: mb_strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Config\Entity\Query\Condition->compile() (line 39 of /core/lib/Drupal/Core/Config/Entity/Query/Condition.php)

j_s’s picture

Deprecated function: mb_strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Config\Entity\Query\Condition->compile() (line 39 of /core/lib/Drupal/Core/Config/Entity/Query/Condition.php)

The patch provided with MR!2585 in 3301613 fixed this error for me.

prabuela’s picture

StatusFileSize
new660 bytes
vincent wasswa’s picture

Version: 11.x-dev » 10.2.x-dev
Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new19.32 KB

Attached is a proposed patch for this issue.

smustgrave’s picture

Version: 10.2.x-dev » 11.x-dev
Priority: Major » Normal
Status: Needs review » Needs work

Not sure what's wrong with the patch but appears to be adding files that already exist.

If going to try a new solution should be documented in the issue summary or in the comment about new approach and why it's better.

Was previously tagged for steps to reproduce + tests which are still needed.

Also patches are being phased out.

Thanks.

vincent wasswa’s picture

vincent wasswa’s picture

Version: 11.x-dev » 10.2.x-dev
StatusFileSize
new1.45 KB

Help fi this issue in Drupal 10

Version: 10.2.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

biancaradu27’s picture

geek-merlin’s picture

I ran into this too and debugged it.

- YES (at least from my case) it looks like this should NOT be silenced, because it would hide an underlying issue.
- NO, it is not wontfix, any such warning means that a warning should be emitted somewhere else already, which is a bug.

How to debug

(might go into a docs page "How to debug backtraces in theming")
- Note the full backtrace and publish it
- It contains sth like this:

Drupal\Component\Utility\Html::getUniqueId(NULL) (Line: 42)
__TwigTemplate_0818f4f8612ad478e98a373e283b0d1d->doDisplay(Array, Array) (Line: 360)

which means that the template with the long name called the function above in template line 42 (!)
- Note the full template and publish it. (without this, the trace is likely useless.)
- Look on line 42 what is missing.

Example

In my case the template had top line
/* core/modules/navigation/templates/navigation-menu.html.twig */
and line 42 is

        $context["menu_heading_id"] = ("menu--" . \Drupal\Component\Utility\Html::getUniqueId($this->sandbox->ensureToStringAllowed(($context["menu_name"] ?? null), 2, $this->source)));

Also i see this in the backtrace:

twig_render_template('core/modules/navigation/templates/navigation-menu.html.twig', Array) (Line: 348)

Which spots me to this line of custom code:

    $build = [
      '#theme' => 'navigation_menu',
      '#items' => self::getLinkItems($linkTreeList, $cacheabilityCollector),
      '#sorted' => TRUE,
    ];

and the following change fixes my instance of the issue

    $build = [
      '#theme' => 'navigation_menu',
      '#items' => self::getLinkItems($linkTreeList, $cacheabilityCollector),
      '#sorted' => TRUE,
      '#menu_name' => 'dummy',
    ];

The underlying bug is that the template does not emit a missing-value warning, and no default is set.

Hope this helps.

prem suthar’s picture

.

oily made their first commit to this issue’s fork.

jan kellermann made their first commit to this issue’s fork.

jan kellermann’s picture

StatusFileSize
new2.7 KB

I created a new issue fork and MR for D11: https://git.drupalcode.org/project/drupal/-/merge_requests/12682

I collected the existing patches and merged them in this issue fork.

I uploaded the patch for your composer-patch as 3326684-42.patch

But this is only the mitigation. As @geek-merlin wrote in #37: behind every warning waits a bug that should have been fixed before.

oily changed the visibility of the branch 3326684-deprecated-function-mbstrtolower to hidden.

oily’s picture

I just hid a branch because the ...11.x branch is the active one..

uv516’s picture

I got the same error in Drupal 11.2.5.

rajab natshah’s picture

Version: 11.x-dev » main