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
| Comment | File | Size | Author |
|---|---|---|---|
| #42 | 3326684-42.patch | 2.7 KB | jan kellermann |
| #36 | 3326684-35-deprecated_mb_strtolower_passing_null_parameter_string.patch | 673 bytes | biancaradu27 |
| #34 | 3326684-patch.patch | 1.45 KB | vincent wasswa |
| #30 | 3326684_23.patch | 660 bytes | prabuela |
| #26 | 3199.patch | 2.15 KB | sanduhrs |
Issue fork drupal-3326684
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
jumpsuitgreen commentedAttached is a proposed patch for this issue.
Comment #3
jumpsuitgreen commentedDisregard that last patch.
Comment #4
jumpsuitgreen commentedThe 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.
Comment #8
prem suthar commentedResolve The Custom CMD Failed Of Merge.
Comment #9
prem suthar commentedSolved the Failed Patch.
Comment #10
prem suthar commentedComment #11
smustgrave commentedThis 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.
Comment #12
selvakumar-96 commentedDeprecated 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.
Comment #13
selvakumar-96 commentedComment #14
heddnI 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.
Comment #15
mohammad-fayoumiupdating 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.
Comment #16
mohammad-fayoumiComment #17
socialnicheguru commented@Mohammad-Fayoumi is there an interdiff?
nevermind, it is not that big of a patch.
it does apply.
Comment #18
mohammad-fayoumiComment #19
smustgrave commentedWas previously tagged for steps to reproduce and tests which still needs to happen.
Did not review or test.
Comment #20
leo liao commentedComment #21
connbi commentedNew patch for Drupal 10.1.2
Comment #22
abhisekmazumdarI 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.
Comment #23
elc commentedThe 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.
Comment #24
rcodinaThe 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.
Comment #25
rcodinaComment #26
sanduhrsMR !3199 works and looks reasonable to me.
Comment #27
quietone commentedI'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.
Comment #28
ikeigenwijs commentedWe 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)Comment #29
j_s commentedThe patch provided with MR!2585 in 3301613 fixed this error for me.
Comment #30
prabuela commentedComment #31
vincent wasswa commentedAttached is a proposed patch for this issue.
Comment #32
smustgrave commentedNot 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.
Comment #33
vincent wasswa commentedComment #34
vincent wasswa commentedHelp fi this issue in Drupal 10
Comment #36
biancaradu27 commentedComment #37
geek-merlinI 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:
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
Also i see this in the backtrace:
Which spots me to this line of custom code:
and the following change fixes my instance of the issue
The underlying bug is that the template does not emit a missing-value warning, and no default is set.
Hope this helps.
Comment #38
prem suthar commented.
Comment #42
jan kellermann commentedI 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.
Comment #44
oily commentedI just hid a branch because the ...11.x branch is the active one..
Comment #45
uv516 commentedI got the same error in Drupal 11.2.5.
Comment #46
rajab natshah