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
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 3414906-10.patch | 902 bytes | swentel |
| #6 | Screenshot 2024-01-16 at 10.28.30.png | 26 KB | heikkiy |
| #5 | Screenshot 2024-01-16 at 10.22.52.png | 17.22 KB | heikkiy |
Comments
Comment #2
heikkiy commentedComment #3
sarwan_verma commentedHi @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,
Comment #4
heikkiy commentedThanks 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.
Comment #5
heikkiy commentedI 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.
Comment #6
heikkiy commentedSorry, was debugging a wrong breakpoint. Here is a screenshot what $variables['content'] is giving me when the error happens.
Comment #7
swentel commentedCould 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.
Comment #8
swentel commentedActually, let's try this, this is even closer to what we had with a better isset check
Comment #9
swentel commentedDarn, wrong patch in 8, sorry!
Comment #10
swentel commentedOk, this should be the right one, sorry for the confusion!
Comment #11
heikkiy commentedThank 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.
Comment #12
nonom commentedPatch #10 works for me. Thanks.
Comment #14
swentel commentedcommitted and pushed.