diff --git a/core/modules/views/templates/views-view-grid.html.twig b/core/modules/views/templates/views-view-grid.html.twig index a5a813c..4ef3dfa 100644 --- a/core/modules/views/templates/views-view-grid.html.twig +++ b/core/modules/views/templates/views-view-grid.html.twig @@ -22,15 +22,40 @@ * @ingroup themeable */ #} +{% + set classes = [ + 'views-view-grid', + options.alignment, + 'cols-' ~ options.columns, + 'clearfix', + ] +%} {% if title %}

{{ title }}

{% endif %} - + {% if options.alignment == 'horizontal' %} {% for row in items %} - + {% if options.row_class_default %} + {% + set row_classes = [ + 'views-row', + 'row-' ~ loop.index, + 'clearfix', + ] + %} + {% endif %} + {% for column in row.content %} - + {% if options.col_class_default %} + {% + set col_classes = [ + 'views-col', + 'col-' ~ loop.index, + ] + %} + {% endif %} + {{ column.content }} {% endfor %} @@ -38,12 +63,29 @@ {% endfor %} {% else %} {% for column in items %} - - {% for row in column.content %} - - {{ row.content }} - - {% endfor %} + {% if options.col_class_default %} + {% + set col_classes = [ + 'views-col', + 'col-' ~ loop.index, + 'clearfix', + ] + %} + {% endif %} + + {% for row in column.content %} + {% if options.row_class_default %} + {% + set row_classes = [ + 'views-row', + 'row-' ~ loop.index, + ] + %} + {% endif %} + + {{ row.content }} + + {% endfor %} {% endfor %} {% endif %} diff --git a/core/modules/views/templates/views-view-summary-unformatted.html.twig b/core/modules/views/templates/views-view-summary-unformatted.html.twig index 9120dd4..5564750 100644 --- a/core/modules/views/templates/views-view-summary-unformatted.html.twig +++ b/core/modules/views/templates/views-view-summary-unformatted.html.twig @@ -9,6 +9,7 @@ * - count: The number of items this summary item represents. * - separator: A separator between each row. * - attributes: HTML attributes for a row. + * - active: A flag indicating whtether the row is active. * - options: Flags indicating how each row should be displayed. This contains: * - count: A flag indicating whether the row's 'count' should be displayed. * - inline: A flag indicating whether the item should be wrapped in an inline @@ -20,11 +21,16 @@ */ #} {% for row in rows %} + {% + set row_classes = [ + row.active ? 'active', + ] + %} {{ options.inline ? ' {% if row.separator -%} {{ row.separator }} {%- endif %} - {{ row.link }} + {{ row.link }} {% if options.count %} ({{ row.count }}) {% endif %} diff --git a/core/modules/views/templates/views-view-summary.html.twig b/core/modules/views/templates/views-view-summary.html.twig index 4d8ed8f..f7f0fcf 100644 --- a/core/modules/views/templates/views-view-summary.html.twig +++ b/core/modules/views/templates/views-view-summary.html.twig @@ -10,6 +10,7 @@ * - link: The summary link text. * - count: The number of items under this grouping. * - attributes: HTML attributes to apply to each row. + * - active: A flag indicating whtether the row is active. * - options: Flags indicating how the summary should be displayed. * This contains: * - count: A flag indicating whether the count should be displayed. @@ -22,7 +23,12 @@
    {% for row in rows %} -
  • {{ row.link }} + {% + set row_classes = [ + row.active ? 'active', + ] + %} +
  • {{ row.link }} {% if options.count %} ({{ row.count }}) {% endif %} diff --git a/core/modules/views/templates/views-view-table.html.twig b/core/modules/views/templates/views-view-table.html.twig index 6b0b26c..62cddaf 100644 --- a/core/modules/views/templates/views-view-table.html.twig +++ b/core/modules/views/templates/views-view-table.html.twig @@ -20,13 +20,24 @@ * - columns: Row column items. Columns are keyed by column number. * - attributes: HTML classes to apply to each column. * - content: The column content. + * - responsive: A flag indicating whether table is responsive. + * - sticky: A flag indicating whether table header is sticky. * * @see template_preprocess_views_view_table() * * @ingroup themeable */ #} - +{% + set classes = [ + 'views-table', + 'views-view-table', + 'cols-' ~ header|length, + responsive ? 'responsive-enabled', + sticky ? 'sticky-enabled', + ] +%} + {% if caption_needed %} {% if caption %} @@ -50,7 +61,16 @@ {% for column in header %} - + {% + set col_classes = [ + column.element_default_classes ? 'views-field', + column.element_default_classes ? 'views-field-' ~ column.field_name, + column.field_label_class ? column.field_label_class, + column.responsive_class ? column.responsive_class, + column.align_class ? column.align_class + ] + %} + {{ column.content }} {% endfor %} @@ -61,7 +81,16 @@ {% for row in rows %} {% for column in row.columns %} - + {% + set col_classes = [ + column.element_default_classes ? 'views-field', + column.element_default_classes ? 'views-field-' ~ column.field_name, + column.align_class ? column.align_class, + column.element_classes ? column.element_classes, + column.responsive_class ? column.responsive_class + ] + %} + {{ column.content }} {% endfor %} diff --git a/core/modules/views/templates/views-view-unformatted.html.twig b/core/modules/views/templates/views-view-unformatted.html.twig index e3fb2e3..68c6e02 100644 --- a/core/modules/views/templates/views-view-unformatted.html.twig +++ b/core/modules/views/templates/views-view-unformatted.html.twig @@ -8,6 +8,7 @@ * - rows: A list of the view's row items. * - attributes: The row's HTML attributes. * - content: The row's content. + * - view: The view object. * * @see template_preprocess_views_view_unformatted() * @@ -18,7 +19,12 @@

    {{ title }}

    {% endif %} {% for row in rows %} - + {% + set row_classes = [ + default_row_class ? 'views-row', + ] + %} + {{ row.content }}
{% endfor %} diff --git a/core/modules/views/templates/views-view.html.twig b/core/modules/views/templates/views-view.html.twig index f839ef9..18fbdb0 100644 --- a/core/modules/views/templates/views-view.html.twig +++ b/core/modules/views/templates/views-view.html.twig @@ -37,7 +37,16 @@ * @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 ebef6f8..fa4329f 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -29,13 +29,6 @@ function template_preprocess_views_view(&$variables) { $variables['id'] = $id; $variables['display_id'] = $view->current_display; - // 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); @@ -55,7 +48,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']; } } @@ -330,10 +322,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]); } } @@ -394,9 +384,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); } } @@ -487,21 +475,24 @@ function template_preprocess_views_view_table(&$variables) { // 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]; + $variables['header'][$field]['element_default_classes'] = TRUE; + } else { + $variables['header'][$field]['element_default_classes'] = FALSE; } + $variables['header'][$field]['field_name'] = $variables['fields'][$field]; + $class = $fields[$field]->elementLabelClasses(0); if ($class) { - $variables['header'][$field]['attributes']['class'][] = $class; + $variables['header'][$field]['field_label_class'] = $class; } // Add responsive header classes. if (!empty($options['info'][$field]['responsive'])) { - $variables['header'][$field]['attributes']['class'][] = $options['info'][$field]['responsive']; + $variables['header'][$field]['responsive_class'] = $options['info'][$field]['responsive']; $responsive = TRUE; } // Add a CSS align class to each field if one was set. if (!empty($options['info'][$field]['align'])) { - $variables['header'][$field]['attributes']['class'][] = drupal_clean_css_identifier($options['info'][$field]['align']); + $variables['header'][$field]['align_class'] = drupal_clean_css_identifier($options['info'][$field]['align']); } // Add a header label wrapper if one was selected. if ($variables['header'][$field]['content']) { @@ -520,9 +511,10 @@ function template_preprocess_views_view_table(&$variables) { $variables['header'][$field]['attributes'] = new Attribute($variables['header'][$field]['attributes']); } - // Add a CSS align class to each field if one was set. + // Define the CSS align class to each field if one was set. + $align_class = NULL; if (!empty($options['info'][$field]['align'])) { - $variables['fields'][$field] .= ' ' . drupal_clean_css_identifier($options['info'][$field]['align']); + $align_class = drupal_clean_css_identifier($options['info'][$field]['align']); } // Render each field into its appropriate column. @@ -540,17 +532,26 @@ function template_preprocess_views_view_table(&$variables) { // 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]; + $column_reference['element_default_classes'] = TRUE; + //$column_reference['attributes']['class'][] = 'views-field'; + //$column_reference['attributes']['class'][] = 'views-field-' . $variables['fields'][$field]; + } else { + $column_reference['element_default_classes'] = FALSE; + } + $column_reference['field_name'] = $variables['fields'][$field]; + + // Add the CSS align class to each field if one was set + if ($align_class) { + $column_reference['align_class'] = $align_class; } if ($classes = $fields[$field]->elementClasses($num)) { - $column_reference['attributes']['class'][] = $classes; + $column_reference['element_classes'] = $classes; } // Add responsive header classes. if (!empty($options['info'][$field]['responsive'])) { - $column_reference['attributes']['class'][] = $options['info'][$field]['responsive']; + $column_reference['responsive_class'] = $options['info'][$field]['responsive']; } // Improves accessibility of complex tables. @@ -615,8 +616,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); @@ -628,11 +627,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'])) { @@ -648,6 +647,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. @@ -655,7 +655,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; } } @@ -673,13 +673,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(); @@ -700,14 +693,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)) { @@ -726,13 +711,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)) { @@ -798,18 +776,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']); } }