Problem/Motivation

After updating DS from 3.32.0 to 3.34.0, my overriden DS twig templates are missing the {{ ds_content_wrapper }} attribute value, resulting in broken HTML.

Steps to reproduce

If you create a ds-1col--node-home-teaser.html.twig theme template with this snippet, it will result in a html element w/o element tag.

<{{ ds_content_wrapper }}{{ attributes.addClass('ds-1col', 'ds-1col-wh-magellan-region', 'clearfix') }}>

Proposed resolution

We may have to revisit this function: ds_preprocess_ds_layout and either initialize the wrappers in another way or do sth like this after setting the wrapper values?

// Restore ds_content_wrapper from config (regression in 8.x-3.34).
if (!isset($variables['ds_content_wrapper'])) {
  $variables['ds_content_wrapper'] = $layout_settings['wrappers']['ds_content'] ?? 'div';
}
CommentFileSizeAuthor
#15 ds-3566323-14.patch1.53 KBswentel

Issue fork ds-3566323

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

mariaioann created an issue. See original summary.

swentel’s picture

Hmm, interesting. Is it the commit from #3564007: Unhandled null value in layout_settings that caused the regression?

swentel’s picture

CRAP, looking at that patch, the logic is completely flawed, my god! Will upload a patch in a couple of minutes!

swentel’s picture

Actually, that patch does seem to be fine, I'm getting confused now myself :) Although this still might be the one that causes it.

#3507312: Fix array_unshift() Error in ds_theme_registry_alter() when running Field Group pre-process before ds_entity_view or #3529867: When merging the build and layout build, merge recursively seem fine I think.

Which Drupal version are you running?

mariaioann’s picture

I'm running Drupal Core 11.3.1.

Problem seems to exist for my overriden in my custom theme ds-1col templates of pattern:
ds-1col--node-home-teaser.html.twig

The corresponding config core.entity_view_display.node.news.home_teaser.yml has the proper config definition for the wrappers:

wrappers:
          metadata: div
          ds_content: div
          right: div

A temporary fix I am using now and resolves the problem is this:

function mymodule_preprocess_ds_1col(&$vars) {
  // Hardcode missing wrapper value to 'div'.
  $vars['ds_content_wrapper'] = 'div';
...

I hope that these help somehow. I am not totally sure whether the problem comes from a misconfiguration of my project, but it was working before the DS update.

swentel’s picture

Configuration looks good, and I'm sure one of the commits between those two tags is causing the problem.

Are you able to quickly test something? (while not using the mymodule_preprocess_ds_1col quick fix part of course)

Can you change this part:

function ds_preprocess_ds_layout(&$variables) {
  $layout_settings = $variables['settings'] ?? [];
  $layout_settings += ['wrappers' => []];
  $variables['settings'] = $layout_settings;

to:

function ds_preprocess_ds_layout(&$variables) {
  $layout_settings = $variables['settings'];
  $layout_settings += ['wrappers' => []];

I want to try and rule out whether this commit is the problem or not.

mariaioann’s picture

Issue summary: View changes
mariaioann’s picture

@swentel I have tested as you suggested but again the same problem.

Please note that the problem is not in my lib/themes/my_theme/templates/node/ds-1col.html.twig, there the variable ds_content_wrapper is properly set.
Problem is only in node display suggestion templates like lib/themes/my_theme/templates/node/ds-1col--node-home-teaser.html.twig.

And if I add this line after outer_wrapper setting in ds_preprocess_ds_layout, it works properly for all templates:

  $variables['outer_wrapper'] = $layout_settings['outer_wrapper'] ?? 'div';
  $variables['ds_content_wrapper'] = $layout_settings['wrappers']['ds_content'] ?? 'div';

It seems that $layout_settings['wrappers']['ds_content'] is not set for my node display suggestion templates.

swentel’s picture

Ok, will try to reproduce this. Thanks for the information so far!
One more additional question. The 'metadata_wrapper' and 'right_wrapper' are fine? (or there's no content in it?)

mariaioann’s picture

Good question, metadata_wrapper and right_wrapper are not set for all ds-1col--XY templates, but are set for ds-1col template most of the times, but not always and not under conditions that I can identify.
E.g. for Image teaser metadata_wrapper is not defined and right_wrapper is defined, but for Image small teaser both are defined. These displays have identical layout, only the image style changes, so there is no reason for the one to have metadata_wrapper set and the other not to have it. And they are both rendered with ds-1col.html.twig template.

Update, I had to resave and re-export core.entity_view_display.node.image.teaser.yml, in order to have the missing `metadata: div` part in the wrappers section. Now it is working.

So, ds_content_wrapper, metadata_wrapper and right_wrapper are not set for all ds-1col--XY templates, but are set for ds-1col template.

fmb’s picture

This seems to occur under Drupal 11.3 (11.2 is fine) when using a suggestion template such as ds-1col--node-home-teaser.html.twig or ds-2col-stacked--node-species.html.twig (it does work when I switch back to ds-2col-stacked.html.twig). Wrappers are empty, only chevrons are output (<>). I was not able to change anything by saving a view display configuration like mariaioann. Actually, the configuration looks perfectly fine, but variables are missing in ds_preprocess_ds_layout(), as though some preprocess or alteration were not triggered when using a suggestion template.

I am currently stuck with Drupal 11.2 on my project because of this bug. I did try to figure out what changed between Drupal 11.2 and 11.3 which could explain this, but of course changes are too vast to process if you do not know how to narrow them down.

swentel’s picture

Interesting to know that 11.2 is fine. My guess is that #3504381: [meta] Convert Template Preprocess hooks to OOP equivalent might be responsible here. And more specific, the commit from #3547806: Convert remaining template_preprocess functions.

#3566261: [regression] custom field twig for second comment fields has null value in comment after 11.3.0 upgrade is an example of a 'wrong' conversion (but not a fix for us, but it has a related problem more or less).

Oh this will be fun to figure out :/

swentel’s picture

So, the 'good' news is that I can reproduce it on 11.3.x, and yes, it only applies to suggestions, the base template is fine.
Now to figure out the fix .. :)

swentel’s picture

Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new1.53 KB

Figured it out! Uploaded a static patch for manual testing locally.

This fixes it on my local setup, would be great if you can confirm it's working on your projects as well!

Note: you need to clear the cache after applying the patch so the theme registry is refreshed. I'll probably add an update hook to the patch too for clearing the caches.

fmb’s picture

Indeed, this patch does fix the issue. Thank you so much!

Would be great if mariaioann could confirm too.

swentel’s picture

All test failures have been fixed + additional fix (more or less the same technique) for field templates.

swentel’s picture

Status: Needs review » Fixed

merged and tagged a new release!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

swentel’s picture

Status: Fixed » Closed (fixed)
mariaioann’s picture

I confirm that the patch fixes the issue. Thank you very much for the fix and the contribution record!