Problem/Motivation

The 'Add views row classes' option in views format settings does not change the output of the view, as documented in #4. The markup is the same whether this is on or off.

Proposed resolution

Assuming that not adding row classes is the expected behaviour (based on #6), remove this option from the UI.

Remaining tasks

  1. Confirm that we don't want to add numbered row classes
  2. Confirm removal of the option will not result in any changes to output of existing views
  3. Remove the checkbox from the UI

User interface changes

Remove this checkbox from the UI.

API changes

n/a

Data model changes

n/a

Release notes snippet

Original IS:

Problem/Motivation

When using the "Table" style plugin, the default_row_class setting is not respected and the classes are not added as expected. I would expect something like views-row-n, views-row-last etc

Proposed resolution

Add back the classes that used to be there in D7.

Remaining tasks

Review the proposed approach + write tests.

CommentFileSizeAuthor
views-row-table-classes.patch1.03 KBbenjy

Comments

benjy’s picture

Title: Default row classes are not added to table » Default row classes are not added when using the table style plugin
dawehner’s picture

+++ b/core/modules/views/src/Plugin/views/style/Table.php
@@ -203,6 +203,28 @@ class Table extends StylePluginBase {
+   */
+  public function getRowClass($row_index) {
+    $classes = [];
+    if ($this->options['default_row_class']) {
+      $row_num = $row_index + 1;
+      $classes = [
+        'views-row',
+        'views-row-' . $row_num,
+        'views-row-' . (($row_num % 2 == 0) ? 'odd' : 'even')
+      ];
+      if ($row_num === 1) {
+        $classes[] = 'views-row-first';
+      }
+      if ($row_num == $this->view->total_rows) {
+        $classes[] = 'views-row-last';
+      }
+    }
+    return parent::getRowClass($row_index) . ' ' . implode(' ', $classes);

So I'm confused: Didn't removed them as CSS 3 can cover all those usecases and we can rely on CSS 3?

benjy’s picture

Well sure CSS3 can cover most of that but what confused me is that the docs in the modal say that the classes will be added:

Add the default row classes like views-row-1 to the output. You can use this to quickly reduce the amount of markup the view provides by default, at the cost of making it more difficult to apply CSS.

Maybe this issue should be a minor doc fix if the consensus is to remove those classes entirely? Although, they're behind a checkbox, I don't see any harm in keeping them.

jabberwooki’s picture

The described problem is not limited to the table style format. Additional tests made (in collaboration with masdongar) on the "Add views row classes" checkbox in the Format setttings popup windows give the following heterogeneous results.

1 - Table
Checking/Unchecking has no effect. In both cases, html structure is

<div class="view ...">
  <div class="view-content">
    <table class="views-table ...">
      <tbody>
        <tr>

2 - Unformatted list
Checked box generates a "views-row" class.

Unchecked

<div class="view ...">
  <div class="view-content">
    <div>

Checked

<div class="view ...">
  <div class="view-content">
    <div class="views-row">

3 - HTML list
No difference. Html structure is

<div class="view ...">
  <div class="view-content">
    <div class="item-list">
      <ul>
        <li>

4 - Grid
Checked box generates a "row-[row number]" class.

Unchecked

<div class="view ...">
  <div class="view-content">
    <div class="views-view-grid ...">
      <div>

Checked

<div class="view ...">
  <div class="view-content">
    <div class="views-view-grid ...">
      <div class="views-row clearfix row-[row number]">

From this point, there are two possible solutions :

- The Drupal community definitely wants to remove class names generation and let CSS3 do the job. So a patch is needed to prevent Unformated list and Grid formats to generate the class names, and to remove the checkbox from the UI.

- The 4 views formats keep on generating their classes, but the checkbox's default value is unchecked. Patch is needed so that Table and HTML list formats generate their respective classes as well.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Needs review » Postponed (maintainer needs more info)

So the only problem here is the missing views-row class? We certainly don't want to add the numbered css classes back. CSS3 totally solves that for us.

duaelfr’s picture

Per #4 I think it's more about consistency.
Having a checkbox that sometimes do something and sometimes not do not send a good signal to the site builders. As we cannot remove it now D8 landed, I suggest that we fix it.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Title: Default row classes are not added when using the table style plugin » Remove 'Add views row classes' setting from all formats as it has no effect on output
Version: 8.9.x-dev » 9.1.x-dev
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active
pameeela’s picture

Issue summary: View changes
pameeela’s picture

Issue tags: +Bug Smash Initiative

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.