Problem/Motivation

I tried to find related issues in the meta #3220021: [meta] Ensure compatibility of Drupal 9 with PHP 8.1 (as it evolves) but failed, sorry if this is a duplicate.
I'm upgrading an inherited project into PHP8.1 and I'm seeing deprecation messages such as

Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\filter\Element\ProcessedText::preRenderText() (line 101 of core/modules/filter/src/Element/ProcessedText.php).

Steps to reproduce

  • Create a render array of type '#processed_text' where the text value is NULL:
$build = [
   '#type' => 'processed_text',
  '#text' => NULL,
  '#format' => 'filtered_html',
];
  • Render it: \Drupal::service('renderer')->renderRoot($build);
  • Unexpected exception is thrown
  • Proposed resolution

    This is an instance of PHP 8.1: Passing null to non-nullable internal function parameters is deprecated and if we were to use string casting null is always converted to an empty string.
    To ensure #text is always treated as a string while preserving error visibility if it’s not set, the following change is recommended:

    $text = (string) $element['#text'];
    

    For an example of why this is preferable, see this demonstration.

    Remaining tasks

    User interface changes

    API changes

    Data model changes

    Release notes snippet

    Issue fork drupal-3294680

    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

    marcoscano created an issue. See original summary.

    marcoscano’s picture

    Assigned: marcoscano » Unassigned
    Status: Active » Needs review
    StatusFileSize
    new601 bytes
    marcoscano’s picture

    makkus183’s picture

    I had the same scenario, got the deprecation warning after upgrading Drupal 9.4.4 Project to PHP 8.1 The patch in #2 solves the issue for me and seems like a simple and rock solid solution to me.
    Thx @marcoscano !

    cilefen’s picture

    Status: Needs review » Postponed (maintainer needs more info)

    Can someone get a stack trace to see why the value is null?

    makkus183’s picture

    @cliefen

    Drupal\filter\Element\ProcessedText::preRenderText(Array)
    call_user_func_array(Array, Array) (Line: 101)
    Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 772)
    Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 363)
    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: 52)
    __TwigTemplate_988bba54303c3720dd69bd9fffefca33->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('modules/contrib/cookiebot/templates/cookiebot-blocked-element-placeholder.html.twig', Array) (Line: 384)
    Drupal\Core\Theme\ThemeManager->render('cookiebot_blocked_element_placeholder', Array) (Line: 422)
    Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 201)
    Drupal\Core\Render\Renderer->render(Array, 1) (Line: 145)
    Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 564)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 146)
    Drupal\Core\Render\Renderer->renderRoot(Array) (Line: 139)
    cookiebot_page_attachments_alter(Array, NULL, NULL) (Line: 562)
    Drupal\Core\Extension\ModuleHandler->alter('page_attachments', Array) (Line: 321)
    Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array) (Line: 288)
    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: 163)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
    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)
    

    It seems that in my case the cookiebot module is causing this.

    cilefen’s picture

    Does this require the alpha cookiebot contributed module? It seems like there is more than one issue here.

    marcoscano’s picture

    I no longer have access to the failing scenario I had, but I agree this is likely an error condition caused by some contrib or custom code sending null in $element['#text']. However, since that's outside of the control of \Drupal\filter\Element\ProcessedText::preRenderText(), shouldn't this method be more defensive and regardless of what is passed in, never call str_replace() with null as the 3rd argument?

    makkus183’s picture

    I agree that the solution provided in the Patch is a good, simple, minimal invasive way to make sure str_replace gets an empty String instead of null, which solves the mentioned warning.

    cilefen’s picture

    I think we've been pushing back in cases like this because calling code is violating APIs. But you may find a counter-example.

    aaronpinero’s picture

    Here is another example of this error; seems to happen as the result of viewing a node revision history(?):

    Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\Component\Utility\Xss::filter() (line 69 of /var/www/html/web/core/lib/Drupal/Component/Utility/Xss.php)
    #0 /var/www/html/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(8192, 'str_replace(): ...', '/var/www/html/w...', 69)
    #1 [internal function]: _drupal_error_handler(8192, 'str_replace(): ...', '/var/www/html/w...', 69)
    #2 /var/www/html/web/core/lib/Drupal/Component/Utility/Xss.php(69): str_replace('\x00', '', NULL)
    #3 /var/www/html/web/modules/composer/diff/src/DiffEntityComparison.php(271): Drupal\Component\Utility\Xss::filter(NULL)
    #4 /var/www/html/web/modules/composer/diff/src/Form/RevisionOverviewForm.php(359): Drupal\diff\DiffEntityComparison->getRevisionDescription(Object(Drupal\node\Entity\Node), Object(Drupal\node\Entity\Node))
    #5 /var/www/html/web/modules/composer/diff/src/Form/RevisionOverviewForm.php(276): Drupal\diff\Form\RevisionOverviewForm->buildRevision(Object(Drupal\Core\Link), Array, Object(Drupal\node\Entity\Node), Object(Drupal\node\Entity\Node))
    #6 [internal function]: Drupal\diff\Form\RevisionOverviewForm->buildForm(Array, Object(Drupal\Core\Form\FormState), Object(Drupal\node\Entity\Node))
    #7 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(531): call_user_func_array(Array, Array)
    #8 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(278): Drupal\Core\Form\FormBuilder->retrieveForm('revision_overvi...', Object(Drupal\Core\Form\FormState))
    #9 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(219): Drupal\Core\Form\FormBuilder->buildForm('Drupal\\diff\\For...', Object(Drupal\Core\Form\FormState))
    #10 /var/www/html/web/modules/composer/diff/src/Controller/NodeRevisionController.php(25): Drupal\Core\Form\FormBuilder->getForm('Drupal\\diff\\For...', Object(Drupal\node\Entity\Node))
    #11 [internal function]: Drupal\diff\Controller\NodeRevisionController->revisionOverview(Object(Drupal\node\Entity\Node))
    #12 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #13 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #14 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #15 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #16 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(159): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #17 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #18 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #19 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #20 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #22 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #23 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(709): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #24 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #25 {main}
    aaronpinero’s picture

    For the error about which I posted, I was able to determine that the offending module is Diff, and the dev version of that module already includes a fix.

    laura.gates’s picture

    When digging for the Diff issue (https://www.drupal.org/project/diff/issues/3206057) as mentioned above and found https://www.drupal.org/project/drupal/issues/3043725 likely this issue is related to that.

    laura.gates’s picture

    I'm not sure if this is helpful - but I'm coming across this in a few different core modules. Mostly Twig, Big Pipe, Filter, and Render

    Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\filter\Element\ProcessedText::preRenderText() (line 101 of /var/www/html/docroot/core/modules/filter/src/Element/ProcessedText.php) #0 /var/www/html/docroot/core/includes/bootstrap.inc(347): _drupal_error_handler_real(8192, 'str_replace(): ...', '/var/www/html/d...', 101) #1 [internal function]: _drupal_error_handler(8192, 'str_replace(): ...', '/var/www/html/d...', 101) #2 /var/www/html/docroot/core/modules/filter/src/Element/ProcessedText.php(101): str_replace(Array, '\n', NULL) #3 [internal function]: Drupal\filter\Element\ProcessedText::preRenderText(Array) #4 /var/www/html/docroot/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array(Array, Array) #5 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(772): Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_ren...', 'exception', 'Drupal\\Core\\Ren...') #6 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(363): Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) #7 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, false) #8 /var/www/html/docroot/core/lib/Drupal/Core/Template/TwigExtension.php(581): Drupal\Core\Render\Renderer->render(Array) #9 /var/www/html/docroot/sites/default/files/assets/php/twig/636d7b6cafe24_block--post-title-info.ht_U06n0dz-rc0u1rV3sxdMsZE_z/u25ot-DICSwehYRNbUjW70QyWwN9tRrBMLRoOmUHlbE.php(85): Drupal\Core\Template\TwigExtension->renderVar(Array) #10 /var/www/html/vendor/twig/twig/src/Template.php(405): __TwigTemplate_404ea349b55bb13d4e87b05e61709f78->doDisplay(Array, Array) #11 /var/www/html/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array) #12 /var/www/html/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array) #13 /var/www/html/docroot/core/themes/engines/twig/twig.engine(55): Twig\Template->render(Array) #14 /var/www/html/docroot/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/custom/g...', Array) #15 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(422): Drupal\Core\Theme\ThemeManager->render('block', Array) #16 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, true) #17 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(157): Drupal\Core\Render\Renderer->render(Array, true) #18 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\Render\Renderer->Drupal\Core\Render\@closure() #19 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(158): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #20 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(172): Drupal\Core\Render\Renderer->renderPlain(Array) #21 /var/www/html/docroot/core/modules/big_pipe/src/Render/BigPipe.php(693): Drupal\Core\Render\Renderer->renderPlaceholder('callback=Drupal...', Array) #22 /var/www/html/docroot/core/modules/big_pipe/src/Render/BigPipe.php(547): Drupal\big_pipe\Render\BigPipe->renderPlaceholder('callback=Drupal...', Array) #23 /var/www/html/docroot/core/modules/big_pipe/src/Render/BigPipe.php(305): Drupal\big_pipe\Render\BigPipe->sendPlaceholders(Array, Array, Object(Drupal\Core\Asset\AttachedAssets)) #24 /var/www/html/docroot/core/modules/big_pipe/src/Render/BigPipeResponse.php(112): Drupal\big_pipe\Render\BigPipe->sendContent(Object(Drupal\big_pipe\Render\BigPipeResponse)) #25 /var/www/html/vendor/symfony/http-foundation/Response.php(381): Drupal\big_pipe\Render\BigPipeResponse->sendContent() #26 /var/www/html/docroot/index.php(20): Symfony\Component\HttpFoundation\Response->send() #27 @main.

    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.

    fathershawn’s picture

    Status: Postponed (maintainer needs more info) » Needs review

    We just saw this after moving to 8.1. As I understand it, this will break in a future version of php and the fix in the patch is a correct and reasonable way to provide the correct type to the core function. Moving this to "needs review" and hoping we can move this to RTBC

    smustgrave’s picture

    Category: Task » Bug report
    Status: Needs review » Needs work
    Issue tags: +Needs Review Queue Initiative

    From reading the comments this seems like this can be caused by contrib modules using the wrong code.

    If we were to add this having test coverage would be good.

    fathershawn’s picture

    Issue summary: View changes

    I'm willing to add a test, but what would the test case be?

    I think the proposed fix, a single line change, is a reasonable and least disruptive change:
    $text = $element['#text'] ?? ''

    Other solutions that occur to me are to cast $element['#text'] to string explicitly, but we haven't been having problems with passing non-strings in general as that would likely throw an exception when the non-string was passed to str_replace().

    joseph.olstad’s picture

    The patch works however I found a way to avoid using the patch.

    In our case, the problem came from our custom theme code, in the exception message I saw near the top of the exception the hint: mymodule_preprocess_ds_1col

    Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\Component\Utility\Html::cleanCssIdentifier() (line 107 of core/lib/Drupal/Component/Utility/Html.php).
    
    Drupal\Component\Utility\Html::cleanCssIdentifier(NULL) (Line: 23)
    mymodule_preprocess_ds_1col(Array, 'ds_1col', Array)

    From there, I grepped (searched) through our custom code and I found the mymodule_preprocess_ds_1col function and in that function we were not validating for a null parameter

    so I fixed the code as follows:

    diff --git a/docroot/themes/custom/rmytheme/includes/content.inc b/docroot/themes/custom/mytheme/includes/content.inc
    index ed348eb9aa..c625023421 100644
    --- a/docroot/themes/custom/mytheme/includes/content.inc
    +++ b/docroot/themes/custom/mytheme/includes/content.inc
    @@ -20,7 +20,12 @@ function mytheme_preprocess_ds_1col(&$variables) {
           $niveau_entity = $niveau_entity->getTranslation($lang_code);
         }
         $niveau = $niveau_entity->description->value;
    -    $classname = 'alerte-niveau-'.mb_strtolower(HTML::cleanCssIdentifier($niveau));
    +    if (empty($niveau)) {
    +      $classname = 'alerte-niveau-';
    +    }
    +    else {
    +      $classname = 'alerte-niveau-'.mb_strtolower(HTML::cleanCssIdentifier($niveau));
    +    }
         $variables['attributes']['class'][] = $classname;
         $variables['niveau'] = $niveau;
       }

    Hope this helps someone else.

    plopesc’s picture

    Version: 9.5.x-dev » 11.x-dev
    Status: Needs work » Needs review
    StatusFileSize
    new1009 bytes
    new1.58 KB

    This is still an issue in 11.x.

    Even if this deprecation message is only triggered by contrib/custom code, I agree that core could be more defensive here.

    Attaching new version of the patch including basic test coverage.

    The last submitted patch, 22: 3294680-22-test-only.patch, failed testing. View results

    smustgrave’s picture

    Status: Needs review » Reviewed & tested by the community

    Lets see what the committers think.

    Thanks for the test case definitely helps this potentially getting in.

    Status: Reviewed & tested by the community » Needs work

    The last submitted patch, 22: 3294680-22.patch, failed testing. View results

    mtaggart@s-5.com’s picture

    I believe the Rules module is the reason I am getting this error as well see the details here: https://www.drupal.org/project/rules/issues/3285721#comment-15186484;

    I attempted patch from comment #2 (https://www.drupal.org/project/drupal/issues/3294680#comment-14597409) with no success.

    laura.gates’s picture

    I patched #2 with drupal 10.1.3 and I so far haven't come across this error message in my logs.

    nicolas bouteille’s picture

    Patch #2 solves it for me when using Twig Tweaks filter {{ $some_value | check_markup('restricted_html') }} if $some_value is null.
    Thanks!

    sanduhrs’s picture

    Status: Needs work » Reviewed & tested by the community

    Patch is working and looks reasonable to me.

    needs-review-queue-bot’s picture

    Status: Reviewed & tested by the community » Needs work

    The Needs Review Queue Bot tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

    Ruslan Piskarov made their first commit to this issue’s fork.

    ruslan piskarov’s picture

    I can't create new branch for 11.x-dev.

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

    sudishth’s picture

    Status: Needs work » Needs review
    smustgrave’s picture

    Status: Needs review » Needs work

    Just fyi #22 still cleanly applied

    haven't really tracked down how NULL gets in there in my scenario, but I wonder if just defaulting to an empty string could make sense here.

    Going off the issue summary this needs to be answered.

    blb’s picture

    I see the same error.

    Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\file\Plugin\Field\FieldType\FileItem->fieldSettingsForm() (line 177 of core/modules/file/src/Plugin/Field/FieldType/FileItem.php).
    Drupal\file\Plugin\Field\FieldType\FileItem->fieldSettingsForm(Array, Object) (Line: 207)
    Drupal\image\Plugin\Field\FieldType\ImageItem->fieldSettingsForm(Array, Object) (Line: 219)
    Drupal\field_ui\Form\FieldConfigEditForm->form(Array, Object) (Line: 107)
    Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm('field_config_edit_form', Object) (Line: 283)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
    Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    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: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    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: 28)
    Drupal\Core\StackMiddleware\ContentLength->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: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    arora.shivani’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new1.14 KB

    Hello, I have created a patch for it. Please review.
    Thank you!

    smustgrave’s picture

    Status: Needs review » Needs work

    Can the question in the proposed solution be answered please.

    jedgar1mx’s picture

    #2 works with 10.2.6

    amitrawat056’s picture

    StatusFileSize
    new192.86 KB

    I encountered the same issue. #38 works for me, Drupal 10.2.6.

    plopesc’s picture

    Issue summary: View changes
    plopesc’s picture

    Issue summary: View changes
    plopesc’s picture

    Status: Needs work » Needs review

    Added steps to reproduce and MR is still valid. Moving to NR

    needs-review-queue-bot’s picture

    Status: Needs review » Needs work
    StatusFileSize
    new1.39 KB

    The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

    plopesc’s picture

    Status: Needs work » Needs review

    MR is back to green after merging 11.x again.

    smustgrave changed the visibility of the branch 3294680-php8.1-deprecation-strreplace to hidden.

    smustgrave changed the visibility of the branch 3294680-D10.1-php8.1-deprecation-strreplace to hidden.

    smustgrave’s picture

    Status: Needs review » Reviewed & tested by the community

    Hiding patches as fix is in MR.

    Ran test-only feature

    1) /builds/issue/drupal-3294680/core/modules/filter/src/Element/ProcessedText.php:106
    str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
    Triggered by:
    * Drupal\Tests\filter\Kernel\FilterAPITest::testProcessedTextElement
      /builds/issue/drupal-3294680/core/modules/filter/tests/src/Kernel/FilterAPITest.php:250
    OK, but there were issues!
    Tests: 8, Assertions: 79, Deprecations: 1.
    

    Not sure if something should be done to address '#text' => NULL, being allowed but current solution does fix the problem.

    alexpott’s picture

    Status: Reviewed & tested by the community » Needs work

    Ideally this would be better fixed in calling modules. It's only triggering a deprecation so we have time to fix it. But if we are going to fix it in core then we should not do so in way that hides the warning if you don't have #text set at all. See comment on MR.

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

    shalini_jha’s picture

    Status: Needs work » Needs review

    I Have addressed the feedback also checked the https://3v4l.org/UuKsj and re-ran the test and its is working as expected. pipeline is also green so moving this NR.
    Kindly review.

    smustgrave’s picture

    Status: Needs review » Needs work

    Appears to be open thread in MR, proposed solution should be tweaked some too.

    shalini_jha’s picture

    Assigned: Unassigned » shalini_jha
    shalini_jha’s picture

    Issue summary: View changes

    Thanks for the review , i have address the feedback as $build['#markup'] is empty string so again no need to add type cast for this . also tried to update the proposed solution according the changes we have added. Kindly review.

    shalini_jha’s picture

    Assigned: shalini_jha » Unassigned
    Status: Needs work » Needs review

    moving this for NR.

    smustgrave’s picture

    Status: Needs review » Needs work

    1 open thread with a good suggestion.

    shalini_jha’s picture

    Status: Needs work » Needs review

    I have reviewed the suggestions provided in this MR and tested the non-convertible value case. It appears that the previous solution didn't work as expected. To address this, I made some adjustments to the $text logic to handle both scenarios correctly.

    Additionally, I’ve added an extra assertion to account for the object case, ensuring that both scenarios are now properly handled. Please take a look and let me know if this approach makes sense.

    Moving this to NR.

    smustgrave’s picture

    Status: Needs review » Reviewed & tested by the community

    Believe feedback has been addressed here.

    catch’s picture

    Status: Reviewed & tested by the community » Needs work

    I don't understand why serialize() is being used here and there doesn't appear to be an explanation either in the MR or the issue summary - can't think of any situation where we'd want to do that either.

    damienmckenna’s picture

    FYI I ran into a similar problem and realized that ProcessedText::preRenderText() was doing a whole load of work if the string was blank, which seemed unnecessary: #3554602: Return early in preRenderText() if text is blank

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

    cleverhoods’s picture

    StatusFileSize
    new1.75 KB

    Adding the file here as well for composer patching.

    Version: 11.x-dev » main

    Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

    Read more in the announcement.