diff -u b/core/modules/views/templates/views-view-grid.html.twig b/core/modules/views/templates/views-view-grid.html.twig --- b/core/modules/views/templates/views-view-grid.html.twig +++ b/core/modules/views/templates/views-view-grid.html.twig @@ -9,6 +9,10 @@ * - view: The view object. * - rows: The rendered view results. * - options: The view plugin style options. + * - row_class_default: A flag indicating whether default classes should be + * used on rows. + * - col_class_default: A flag indicating whether default classes should be + * used on columns. * - items: A list of grid items. Each item contains a list of rows or columns. * The order in what comes first (row or column) depends on which alignment * type is chosen (horizontal or vertical). diff -u b/core/modules/views/templates/views-view-table.html.twig b/core/modules/views/templates/views-view-table.html.twig --- b/core/modules/views/templates/views-view-table.html.twig +++ b/core/modules/views/templates/views-view-table.html.twig @@ -11,6 +11,8 @@ * - attributes: Remaining HTML attributes for the element. * - content: HTML classes to apply to each header cell, indexed by * the header's key. + * - default_classes: A flag indicating whether default classes should be + * used. * - caption_needed: Is the caption tag needed. * - caption: The caption for this table. * - accessibility_description: Extended description for the table details. @@ -20,6 +22,8 @@ * - columns: Row column items. Columns are keyed by column number. * - attributes: HTML classes to apply to each column. * - content: The column content. + * - default_classes: A flag indicating whether default classes should be + * used. * - responsive: A flag indicating whether table is responsive. * - sticky: A flag indicating whether table header is sticky. * @@ -60,8 +64,16 @@ {% if header %} - {% for column in header %} - + {% for key, column in header %} + {% if column.default_classes %} + {% + set column_classes = [ + 'views-field', + 'views-field-' ~ fields[key], + ] + %} + {% endif %} + {{ column.content }} {% endfor %} @@ -71,8 +83,16 @@ {% for row in rows %} - {% for column in row.columns %} - + {% for key, column in row.columns %} + {% if column.default_classes %} + {% + set column_classes = [ + 'views-field', + 'views-field-' ~ fields[key], + ] + %} + {% endif %} + {{ column.content }} {% endfor %} diff -u b/core/modules/views/templates/views-view-unformatted.html.twig b/core/modules/views/templates/views-view-unformatted.html.twig --- b/core/modules/views/templates/views-view-unformatted.html.twig +++ b/core/modules/views/templates/views-view-unformatted.html.twig @@ -9,6 +9,8 @@ * - attributes: The row's HTML attributes. * - content: The row's content. * - view: The view object. + * - default_row_class: A flag indicating whether default classes should be + * used on rows. * * @see template_preprocess_views_view_unformatted() * diff -u b/core/modules/views/templates/views-view.html.twig b/core/modules/views/templates/views-view.html.twig --- b/core/modules/views/templates/views-view.html.twig +++ b/core/modules/views/templates/views-view.html.twig @@ -4,14 +4,7 @@ * Default theme implementation for main view template. * * Available variables: - * - attributes: Remaining HTML attributes for the element including: - * - class: HTML classes that can be used to style contextually - * through CSS, including: - * - view - * - view-[css_name] - * - view-id-[view_name] - * - view-display-id-[display_name] - * - view-dom-id-[dom_id] + * - attributes: Remaining HTML attributes for the element. * - css_name: A css-safe version of the view name. * - css_class: The user-specified classes names, if any. * - header: The optional header. @@ -31,6 +24,8 @@ * view content. * - attachment_after: An optional attachment view to be displayed after the * view content. + * - dom_id: Unique id for every view being printed to give unique class for + * Javascript. * * @see template_preprocess_views_view() * diff -u b/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc --- b/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -472,12 +472,9 @@ $variables['header'][$field]['content'] = \Drupal::l($label, new Url('', [], $link_options)); } + $variables['header'][$field]['default_classes'] = $fields[$field]->options['element_default_classes']; // Set up the header label class. $variables['header'][$field]['attributes'] = array(); - if ($fields[$field]->options['element_default_classes']) { - $variables['header'][$field]['attributes']['class'][] = 'views-field'; - $variables['header'][$field]['attributes']['class'][] = 'views-field-' . $variables['fields'][$field]; - } $class = $fields[$field]->elementLabelClasses(0); if ($class) { $variables['header'][$field]['attributes']['class'][] = $class; @@ -525,12 +522,9 @@ // Reference to the column in the loop to make the code easier to read. $column_reference =& $variables['rows'][$num]['columns'][$column]; + $column_reference['default_classes'] = $fields[$field]->options['element_default_classes']; // Add field classes. $column_reference['attributes'] = array(); - if ($fields[$field]->options['element_default_classes']) { - $column_reference['attributes']['class'][] = 'views-field'; - $column_reference['attributes']['class'][] = 'views-field-' . $variables['fields'][$field]; - } if ($classes = $fields[$field]->elementClasses($num)) { $column_reference['attributes']['class'][] = $classes;