+ {%
+ set row_classes = [
+ default_row_class ? 'views-row',
+ ]
+ %}
+
{% endfor %}
diff --git a/core/modules/views/templates/views-view.html.twig b/core/modules/views/templates/views-view.html.twig
index 46c7e0a..a62bde1 100644
--- a/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,13 +24,24 @@
* 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()
*
* @ingroup themeable
*/
#}
-
+{%
+ set classes = [
+ 'view',
+ 'view-' ~ id|clean_class,
+ 'view-id-' ~ id,
+ 'view-display-id-' ~ display_id,
+ dom_id ? 'view-dom-id-' ~ dom_id,
+ ]
+%}
+
{{ title_prefix }}
{% if title %}
{{ title }}
diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc
index d2e11d3..7db50c8 100644
--- a/core/modules/views/views.theme.inc
+++ b/core/modules/views/views.theme.inc
@@ -34,13 +34,6 @@ function template_preprocess_views_view(&$variables) {
// for an example of this.
$variables['title'] = '';
- // Basic classes.
- $variables['attributes']['class'] = array();
- $variables['attributes']['class'][] = 'view';
- $variables['attributes']['class'][] = 'view-' . Html::cleanCssIdentifier($variables['id']);
- $variables['attributes']['class'][] = 'view-id-' . $variables['id'];
- $variables['attributes']['class'][] = 'view-display-id-' . $variables['display_id'];
-
$css_class = $view->display_handler->getOption('css_class');
if (!empty($css_class)) {
$variables['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class);
@@ -60,7 +53,6 @@ function template_preprocess_views_view(&$variables) {
// identifier for each view. This identifier is written to both
// drupalSettings and the DIV wrapper.
$variables['dom_id'] = $view->dom_id;
- $variables['attributes']['class'][] = 'view-dom-id-' . $variables['dom_id'];
}
}
@@ -337,10 +329,8 @@ function template_preprocess_views_view_summary(&$variables) {
}
$variables['rows'][$id]->url = _url($view->getUrl($args, $base_path), $url_options);
$variables['rows'][$id]->count = intval($row->{$argument->count_alias});
- if (isset($active_urls[$variables['rows'][$id]->url])) {
- $variables['rows'][$id]->attributes['class'][] = 'active';
- }
$variables['rows'][$id]->attributes = new Attribute($variables['rows'][$id]->attributes);
+ $variables['rows'][$id]->active = isset($active_urls[$variables['rows'][$id]->url]);
}
}
@@ -401,9 +391,7 @@ function template_preprocess_views_view_summary_unformatted(&$variables) {
}
$variables['rows'][$id]->url = _url($view->getUrl($args, $base_path), $url_options);
$variables['rows'][$id]->count = intval($row->{$argument->count_alias});
- if (isset($active_urls[$variables['rows'][$id]->url])) {
- $variables['rows'][$id]->attributes['class'][] = 'active';
- }
+ $variables['rows'][$id]->active = isset($active_urls[$variables['rows'][$id]->url]);
$variables['rows'][$id]->attributes = new Attribute($variables['rows'][$id]->attributes);
}
}
@@ -491,12 +479,9 @@ function template_preprocess_views_view_table(&$variables) {
$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;
@@ -544,14 +529,16 @@ function template_preprocess_views_view_table(&$variables) {
// 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'];
+
+ // Set the field key to the column so it can be used for adding classes
+ // in a template.
+ $column_reference['fields'][] = $variables['fields'][$field];
+
// Add field classes.
if (!isset($column_reference['attributes'])) {
$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;
@@ -624,8 +611,6 @@ function template_preprocess_views_view_table(&$variables) {
$variables['rows'][$num]['attributes'] = new Attribute($variables['rows'][$num]['attributes']);
}
- $variables['attributes']['class'][] = 'views-table';
- $variables['attributes']['class'][] = 'views-view-table';
if (empty($variables['rows']) && !empty($options['empty_table'])) {
$build = $view->display_handler->renderArea('empty');
$variables['rows'][0]['columns'][0]['content'] = drupal_render($build);
@@ -637,11 +622,11 @@ function template_preprocess_views_view_table(&$variables) {
));
}
+ $variables['sticky'] = FALSE;
if (!empty($options['sticky'])) {
$variables['view']->element['#attached']['library'][] = 'core/drupal.tableheader';
- $variables['attributes']['class'][] = "sticky-enabled";
+ $variables['sticky'] = TRUE;
}
- $variables['attributes']['class'][] = 'cols-' . count($variables['header']);
// Add the caption to the list if set.
if (!empty($handler->options['caption'])) {
@@ -657,6 +642,7 @@ function template_preprocess_views_view_table(&$variables) {
$variables['description'] = $handler->options['description'];
$variables['caption_needed'] |= !empty($variables['summary']) || !empty($variables['description']);
+ $variables['responsive'] = FALSE;
// If the table has headers and it should react responsively to columns hidden
// with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM
// and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors.
@@ -664,7 +650,7 @@ function template_preprocess_views_view_table(&$variables) {
$variables['view']->element['#attached']['library'][] = 'core/drupal.tableresponsive';
// Add 'responsive-enabled' class to the table to identify it for JS.
// This is needed to target tables constructed by this function.
- $variables['attributes']['class'][] = 'responsive-enabled';
+ $variables['responsive'] = TRUE;
}
}
@@ -682,13 +668,6 @@ function template_preprocess_views_view_grid(&$variables) {
$options = $variables['options'] = $variables['view']->style_plugin->options;
$horizontal = ($options['alignment'] === 'horizontal');
- $variables['attributes']['class'] = array(
- 'views-view-grid',
- $options['alignment'],
- 'cols-' . $options['columns'],
- 'clearfix',
- );
-
$col = 0;
$row = 0;
$items = array();
@@ -709,14 +688,6 @@ function template_preprocess_views_view_grid(&$variables) {
// Create attributes for rows.
if (!$horizontal || ($horizontal && empty($items[$row]['attributes']))) {
$row_attributes = array('class' => array());
- // Add default views row classes.
- if ($options['row_class_default']) {
- $row_attributes['class'][] = 'views-row';
- $row_attributes['class'][] = 'row-' . ($row + 1);
- if ($horizontal) {
- $row_attributes['class'][] = 'clearfix';
- }
- }
// Add custom row classes.
$row_class = array_filter(explode(' ', $variables['view']->style_plugin->getCustomClass($result_index, 'row')));
if (!empty($row_class)) {
@@ -735,13 +706,6 @@ function template_preprocess_views_view_grid(&$variables) {
if ($horizontal || (!$horizontal && empty($items[$col]['attributes']))) {
$col_attributes = array('class' => array());
// Add default views column classes.
- if ($options['col_class_default']) {
- $col_attributes['class'][] = 'views-col';
- $col_attributes['class'][] = 'col-' . ($col + 1);
- if (!$horizontal) {
- $col_attributes['class'][] = 'clearfix';
- }
- }
// Add custom column classes.
$col_class = array_filter(explode(' ', $variables['view']->style_plugin->getCustomClass($result_index, 'col')));
if (!empty($col_class)) {
@@ -807,18 +771,15 @@ function template_preprocess_views_view_unformatted(&$variables) {
$style = $view->style_plugin;
$options = $style->options;
- $default_row_class = isset($options['default_row_class']) ? $options['default_row_class'] : FALSE;
+ $variables['default_row_class'] = isset($options['default_row_class']) ? $options['default_row_class'] : FALSE;
foreach ($rows as $id => $row) {
$variables['rows'][$id] = array();
$variables['rows'][$id]['content'] = $row;
$variables['rows'][$id]['attributes'] = array();
- if ($default_row_class) {
- $variables['rows'][$id]['attributes']['class'][] = 'views-row';
- }
+ $variables['rows'][$id]['attributes'] = new Attribute($variables['rows'][$id]['attributes']);
if ($row_class = $view->style_plugin->getRowClass($id)) {
- $variables['rows'][$id]['attributes']['class'][] = $row_class;
+ $variables['rows'][$id]['attributes']->addClass($row_class);
}
- $variables['rows'][$id]['attributes'] = new Attribute($variables['rows'][$id]['attributes']);
}
}