0

I am trying migrate my Drupal 8.9 site to Drupal 9+ and I am stuck with an error its cause I am not able to hunt down. On almost every page I get the following PHP exception:

Twig\Error\RuntimeError: The "replace" filter expects an array or 

"Traversable" as replace values, got "string" in "__string_template__faabd18c7a37a1e54d0ef10115b24022e72bc201187fff502de48bf58589321f" at line 2. in twig_replace_filter() (line 554 of /var/customers/webs/freigeist/www9/vendor/twig/twig/src/Extension/CoreExtension.php).

__TwigTemplate_75ee113db094d36d71f294529e9d7055b2065bf116719e9a04b7e4795be3121d->doDisplay() (Line: 405)
Twig\Template->displayWithErrorHandling() (Line: 378)
Twig\Template->display() (Line: 390)
Twig\Template->render() (Line: 45)
Twig\TemplateWrapper->render() (Line: 235)
Drupal\Core\Template\TwigEnvironment->renderInline() (Line: 52)
Drupal\Core\Render\Element\InlineTemplate::preRenderInlineTemplate()
call_user_func_array() (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 786)
Drupal\Core\Render\Renderer->doCallback() (Line: 377)
Drupal\Core\Render\Renderer->doRender() (Line: 201)
Drupal\Core\Render\Renderer->render() (Line: 157)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 578)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 158)
Drupal\Core\Render\Renderer->renderPlain() (Line: 419)
Drupal\views\Plugin\views\PluginBase->viewsTokenReplace() (Line: 1356)
Drupal\views\Plugin\views\field\FieldPluginBase->renderAltered() (Line: 1249)
Drupal\views\Plugin\views\field\FieldPluginBase->renderText() (Line: 1177)
Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender() (Line: 238)
template_preprocess_views_view_field() (Line: 287)
Drupal\Core\Theme\ThemeManager->render() (Line: 436)
Drupal\Core\Render\Renderer->doRender() (Line: 201)
Drupal\Core\Render\Renderer->render() (Line: 1745)
Drupal\views\Plugin\views\field\FieldPluginBase->theme() (Line: 778)
Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow()
call_user_func_array() (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 786)
Drupal\Core\Render\Renderer->doCallback() (Line: 377)
Drupal\Core\Render\Renderer->doRender() (Line: 201)
Drupal\Core\Render\Renderer->render() (Line: 717)
Drupal\views\Plugin\views\style\StylePluginBase->renderFields() (Line: 584)
Drupal\views\Plugin\views\style\StylePluginBase->renderGrouping() (Line: 475)
Drupal\views\Plugin\views\style\StylePluginBase->render() (Line: 2170)
Drupal\views\Plugin\views\display\DisplayPluginBase->render() (Line: 1533)
Drupal\views\ViewExecutable->render() (Line: 183)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1630)
Drupal\views\ViewExecutable->executeDisplay() (Line: 81)
Drupal\views\Element\View::preRenderViewElement()
call_user_func_array() (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 786)
Drupal\Core\Render\Renderer->doCallback() (Line: 377)
Drupal\Core\Render\Renderer->doRender() (Line: 201)
Drupal\Core\Render\Renderer->render() (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 578)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 57)
Drupal\Core\StackMiddleware\Session->handle() (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 191)
Drupal\page_cache\StackMiddleware\PageCache->fetch() (Line: 128)
Drupal\page_cache\StackMiddleware\PageCache->lookup() (Line: 82)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 717)
Drupal\Core\DrupalKernel->handle() (Line: 19)

I found out that the error might be theme related (I am on Bootstrap). And on some pages I could narrow it down to the system block 'site_branding': Disabling this block makes the error disappear on some pages, but not on all.

My first guess was, that this might be an twig compatibility issue (may be in my bootstrap sub-theme), but it occurs also when I use other themes. So I am completely lost here.

How could I debug this error? Does the error message show, which component could be the cause of the error? Can anybody point out, which change between Drupal 8 and 9 could be responsible of the error?

3
  • What is the question? What is unclear about the error message? BTW the template name looks not like a real Twig template, more like an inline template in PHP. You could try to find it in a full error message with stack trace.
    – 4k4
    Oct 31 '21 at 10:33
  • @4k4 You are right, I did not ask a clear question, I think it was too late yesterday. I tried to make my questions clearer now. Should I use the devel module to stack trace.
    – user5950
    Oct 31 '21 at 13:03
  • You can enable full error messages in Drupal core: /admin/config/development/logging
    – 4k4
    Oct 31 '21 at 13:34
4

This is the last line in the stack trace before the render pipeline is throwing the error:

Drupal\views\Plugin\views\PluginBase->viewsTokenReplace() (Line: 1356)

This might be caused by a |replace filter rewriting a Views field in the View you are trying to display as main content of the page.

See the deprecation warning in Drupal 8.9 (Twig 1.x):

function twig_replace_filter($str, $from, $to = null) {
  if (\is_string($from) && \is_string($to)) {
    @trigger_error('Using "replace" with character by character replacement is deprecated since version 1.22 and will be removed in Twig 2.0', E_USER_DEPRECATED);
  

https://api.drupal.org/api/drupal/vendor%21twig%21twig%21src%21Extension%21CoreExtension.php/function/twig_replace_filter/8.9.x

Drupal 9 has upgraded to Twig 2.x

https://api.drupal.org/api/drupal/vendor%21twig%21twig%21src%21Extension%21CoreExtension.php/function/twig_replace_filter/9.2.x

2
  • Great, that helped a lot. It was the one dirty hack, in the main View I forgot about. How did you deduce however, that ´Drupal\views\Plugin\views\PluginBase->viewsTokenReplace() (Line: 1356)´ was the last line before the error?
    – user5950
    Oct 31 '21 at 21:27
  • 1
    The lines above are rendering methods which only run because line 419 of this Views plugin base class is starting a rendering process providing the data to be rendered. So it's very likely that this data is causing the issue, unless a faulty template had been involved in rendering the data. But then the error message had contained the template name, which would have made debugging much easier.
    – 4k4
    Oct 31 '21 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.