Problem/Motivation

After upgrading DS from 3.15 to 3.17 our site broke completely. There is an error in preprocess which prevents the site from opening at all. Tested also using the dev version but it does not fix the issue, dev commit is dev-3.x a748dcc.

The error stacktrace is:

The website encountered an unexpected error. Try again later.

Error: Cannot use object of type Drupal\Core\Render\Markup as array in ds_theme_suggestions_alter() (line 656 of modules/contrib/ds/ds.module).

Drupal\Core\Extension\ModuleHandler->alter('theme_suggestions', Array, Array, 'region') (Line: 87)
Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler->alter(Array, Array, Array, 'region') (Line: 72)
Drupal\preprocess\PreprocessManager->getSuggestions('region', Array) (Line: 82)
Drupal\preprocess\PreprocessManager->preprocess('region', Array) (Line: 23)
preprocess_preprocess(Array, 'region', Array)
call_user_func_array('preprocess_preprocess', Array) (Line: 261)
Drupal\Core\Theme\ThemeManager->render('region', Array) (Line: 536)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array) (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 86)
__TwigTemplate_5d4cc774e67a72f7d7ec6ecdb402f0d4->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array) (Line: 38)
Twig\TemplateWrapper->render(Array) (Line: 39)
twig_render_template('themes/contrib/gin/templates/page/page.html.twig', Array) (Line: 348)
Drupal\Core\Theme\ThemeManager->render('page', Array) (Line: 480)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array) (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 87)
__TwigTemplate_ab03f1f59b72f1713a6709c9deba8f83->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array) (Line: 38)
Twig\TemplateWrapper->render(Array) (Line: 39)
twig_render_template('themes/contrib/gin/templates/html.html.twig', Array) (Line: 348)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 480)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array) (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 159)
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: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
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)

The error comes from Gin but I also tested Claro and it doesn't fix the error. We also have Hook event dispatcher and Preprocess modules involved which be related.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

HeikkiY created an issue. See original summary.

heikkiy’s picture

Issue summary: View changes
sarwan_verma’s picture

StatusFileSize
new2.44 KB

Hi @HeikkiY,
I have fixed this issue "Cannot use object of type Drupal\Core\Render\Markup as array in ds_theme_suggestions_alter()" and also attached patch ,please review and verify,

heikkiy’s picture

Thanks a lot for the quick reply @sarwan_verma. I tested the patch and it applies correctly against 3.17 but unfortunately it doesn't fix the error.

Our guess is that this is related to the following line: https://git.drupalcode.org/project/ds/-/blob/8.x-3.x/ds.module?ref_type=...

Most likely $variables['content']['#ds_configuration']['layout'] has been previously an array but is now returning an object. I'll try to debug what it's returning for me at the moment.

heikkiy’s picture

StatusFileSize
new17.22 KB

I debugged this and I think this is related to preprocessing Gin / Claro because the content array is not there at all but it contains a html array.

I'll attach what the variable contains when I add a breakpoint to ds_theme_suggestions_alter() during the error. I will attach an image from xdebug what $variables is currently giving me.

heikkiy’s picture

StatusFileSize
new26 KB

Sorry, was debugging a wrong breakpoint. Here is a screenshot what $variables['content'] is giving me when the error happens.

swentel’s picture

Status: Active » Needs review
StatusFileSize
new867 bytes

Could you try this patch? It more or less goes back to what we had before. It's definitely the if check we should fix here.

swentel’s picture

StatusFileSize
new1.52 KB

Actually, let's try this, this is even closer to what we had with a better isset check

swentel’s picture

Darn, wrong patch in 8, sorry!

swentel’s picture

StatusFileSize
new902 bytes

Ok, this should be the right one, sorry for the confusion!

heikkiy’s picture

Thank you @swentel. I can confirm that the latest patch from #10 fixes my issue and the site opens again. I will do a bit more testing in our staging environment but I would be willing to mark this as RTBC.

nonom’s picture

Status: Needs review » Reviewed & tested by the community

Patch #10 works for me. Thanks.

  • swentel committed 34e88d4e on 8.x-3.x
    Issue #3414906 by swentel, sarwan_verma, HeikkiY: Cannot use object of...
swentel’s picture

Status: Reviewed & tested by the community » Fixed

committed and pushed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.