I have noticed that on all twig templates the way to add values to the class attribute for the wrapper container is similar to this <{{ outer_wrapper }}{{ attributes.addClass('ds-2col', 'clearfix') }}>. Which output the following code for me class="contextual-region view-mode-teaser ds-2col clearfix". As you can see on this code we are missing information like: node type, unpublished, sticky, etc.

I believe these classes are necessary for a proper style of a site and they used to be present on previous versions of Display Suite module.

Would it be possible to add them back please?

Thank you so much.

CommentFileSizeAuthor
#8 2639984-7.patch776 bytesaspilicious
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

altrugon created an issue. See original summary.

aspilicious’s picture

I have to look at how core adds those classes... If they still exist in D8

altrugon’s picture

@aspilicious on the Classy theme you can see how those classes get added on node.html.twig.

This is the work around that we have come with so far:

/**
 * Process entity view.
 */
function myhook_preprocess_ds_entity_view(&$variables){
  if (is_object($variables['content']['#node'])){
    $variables['content']['#attributes']['class'][] = 'node--type-' . Drupal\Component\Utility\Html::cleanCssIdentifier($variables['content']['#node']->getType());
  }
}
aspilicious’s picture

As each template can be overridden you can add those classes your zelf, not sure if I have to add them by default...

Although thats probably the best idea...

altrugon’s picture

I did try to do it on the template first like node.html.twig does on the Classy node, however the object node was missing.

Perhaps you are right and these classes shouldn't be added by default since now there is the Stable theme that add not classes at all, but would it be possible to pass the "node" object to the template, or add an option on the UI to have the classes added/removed?

aspilicious’s picture

the templates are entity agnostic, once I have some time I'll try to figure out What the name of the element is holding the entity

aspilicious’s picture

You can print the variables in template_preprocess_ds_entity_view(&$variables) to see what is available.
And you can potentially override template_preprocess_ds_entity_view in your theme function to add what you need.

aspilicious’s picture

Status: Active » Needs review
FileSize
776 bytes

The patch in combination with a: ds-2col--node.html.twig does the trick.
So if tests are green I'll commit this patch.
We should probably document this somewhere...

{#
/**
 * @file
 * Display Suite 2 column template.
 *
 * Available variables:
 * - outer_wrapper: outer wrapper element
 * - left_wrapper: wrapper element around left region
 * - right_wrapper: wrapper element around right region
 * - attributes: layout attributes
 * - left_attributes: attributes for left region
 * - right_attributes: attributes for right region
 * - left: content of left region
 * - right: content of right region
 */
#}

{%
set classes = [
  'node',
  'node--type-' ~ node.bundle|clean_class,
  node.isPromoted() ? 'node--promoted',
  node.isSticky() ? 'node--sticky',
  not node.isPublished() ? 'node--unpublished',
]
%}

<{{ outer_wrapper }}{{ attributes.addClass('ds-2col', 'clearfix', classes) }}>

{{ title_suffix.contextual_links }}

<{{ left_wrapper }}{{ left_attributes.addClass('group-left') }}>
{{ left }}
</{{ left_wrapper }}>

<{{ right_wrapper }}{{ right_attributes.addClass('group-right') }}>
{{ right }}
</{{ right_wrapper }}>

</{{ outer_wrapper }}>

aspilicious’s picture

Status: Needs review » Fixed

AND comitted, have fun :)

  • aspilicious committed 02a3af2 on 8.x-2.x
    Issue #2639984: DS templates are missing "node" classes
    

Status: Fixed » Closed (fixed)

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