Problem/Motivation

When configuring a view that concerns a field that allows multiple values, unchecking the Display all values in the same row checkbox under the field settings results in each value getting a row of its own. However, each row displays all values.

To reproduce

  1. Edit the Article content type's image field storage to allow unlimited values
  2. Create a view containing article title, and the image field.
  3. Under the image field settings in the view, expand the Multiple field settings
  4. Uncheck the Display all values in the same row

Note that now each node gets a row for each image (as it should). However, instead of displaying only one image per row, all images are displayed in each row.

Note that this is not specific to image fields ( I also tested with integer list fields), nor does it appear to be specific to the display type selected.

Proposed resolution

Each row should only display one value in a multiple value field configuration.

Remaining tasks

Fix the issue.

User interface changes

API changes

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because multiple value field views are not working as expected
Unfrozen changes Unfrozen because it only changes multiple value field views to work as they previously did
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

urgs

jhedstrom’s picture

Issue tags: +Needs tests
dawehner’s picture

Totally agree that this sounds like a bug we have to fix.

geertvd’s picture

FileSize
950 bytes

This fixed it for me.
Although I'm not sure what they are trying to do there, in #1758616: Implement core handling for limiting displayed deltas they are actually talking about moving this logic to the field formatter so maybe this one should be marked as a duplicate instead.

dawehner’s picture

Status: Active » Needs review

Thank you for the patch!

Let's first see whether this breaks other things.

In general we really need tests to ensure that things don't break anymore in the future.

geertvd’s picture

FileSize
7.18 KB

Added the test, first time I'm writing one of these, hopefully it's somewhat correct.

geertvd’s picture

FileSize
7.18 KB

fixed, wrong issue id in filename

jhedstrom’s picture

@geertvd could you upload the test as a separate file so the current failing behavior can be illustrated?

geertvd’s picture

FileSize
5.91 KB

Here you go

Status: Needs review » Needs work

The last submitted patch, 9: 2397495-9-tests.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Thanks! Back to needs review as the test in #9 was expected to fail.

  1. +++ b/core/modules/views/src/Tests/GroupRowsTest.php
    @@ -0,0 +1,87 @@
    +/**
    

    Need a line break here.

  2. +++ b/core/modules/views/src/Tests/GroupRowsTest.php
    @@ -0,0 +1,87 @@
    +    // Create content type with unlimited text field
    ...
    +    // Create an instance of the text field on the content type
    ...
    +  function testGroupRows() {
    

    Those comments should have a period at the end. This is technically testing 'ungrouped' rows. Perhaps we should also add a test that checks the single-row (grouping) of multiple-value fields?

geertvd’s picture

Good point, added the second test and fixed some of the code formatting issues.

The last submitted patch, 12: 2397495-12-tests.patch, failed testing.

dawehner’s picture

  1. +++ b/core/modules/views/src/Tests/GroupRowsTest.php
    @@ -0,0 +1,98 @@
    + * Definition of Drupal\views\Tests\GroupRowsTest.
    ...
    +class GroupRowsTest extends ViewTestBase {
    

    I'd be great to move this at least into the handlers test namespace and prefix the class with Field so its more clear what this is about.

  2. +++ b/core/modules/views/src/Tests/GroupRowsTest.php
    @@ -0,0 +1,98 @@
    +
    +  protected $node_type;
    +
    +  protected $field_name;
    +
    +  protected $field_storage;
    +
    +  protected $field;
    

    it would be great to document them + camelcase them :(

dawehner’s picture

Priority: Normal » Critical

This fixes failures of #2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency so let's bump this to critical and for itself this is pretty WTF that it doesn't work (so for itself I would argue this is major)

geertvd’s picture

  1. Moved to handler namespace and renamed class to "FieldGroupRowsTest"
  2. I moved those variables to the setUp function, they are also described there.

Status: Needs review » Needs work

The last submitted patch, 17: 2397495-17-complete.patch, failed testing.

The last submitted patch, 17: 2397495-17-tests.patch, failed testing.

geertvd’s picture

This one should apply

geertvd’s picture

Status: Needs work » Needs review
dawehner’s picture

This looks really fine!

I would have created just one test view and manipulated the checkbox manually in code, but having two exported views is fine.

Here are two left nitpicks!

  1. +++ b/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php
    @@ -0,0 +1,90 @@
    + * Definition of Drupal\views\Tests\Handler\GroupRowsTest.
    

    Ensure that we point to the right classname in the documentation here :) (got confused for a while ... ). When you change this already use "Contains \Drupal...."

  2. +++ b/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php
    @@ -0,0 +1,90 @@
    +/**
    + * Tests the "Display all values in the same row" setting.
    + *
    

    Can we put an @see \Drupal\views\Plugin\views\field\Field in here? This would help with understand where this setting is coming from.

  3. +++ b/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php
    @@ -0,0 +1,90 @@
    +  function testGroupRows() {
    ...
    +  function testUngroupedRows() {
    

    you could change it to use "public ..."

The last submitted patch, 20: 2397495-20-tests.patch, failed testing.

geertvd’s picture

Fixed those small issues.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

The last submitted patch, 24: 2397495-24-tests.patch, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php
@@ -0,0 +1,92 @@
+  /**
+   * Testing when "Display all values in the same row" is checked.
+   */
+  public function testGroupRows() {
+    $this->drupalGet('test-group-rows');
+    $result = $this->xpath('//div[contains(@class, "views-field-field-views-testing-group-")]/div');
+
+    $rendered_value = array();
+    foreach ($result as $row) {
+      $rendered_value[] = (string) $row[0];
+    }
+    $this->assertEqual(array('a, b, c'), $rendered_value);
+  }
+
+  /**
+   * Testing when "Display all values in the same row" is unchecked.
+   */
+  public function testUngroupedRows() {
+    $this->drupalGet('test-ungroup-rows');
+    $result = $this->xpath('//div[contains(@class, "views-field-field-views-testing-group-")]/div');
+    $rendered_value = array();
+    foreach ($result as $row) {
+      $rendered_value[] = (string) $row[0];
+    }
+    $this->assertEqual(array('a', 'b', 'c'), $rendered_value);
+  }

I think this would be a better test if there was only one view and one test method - but the test just changes the group_rows value. Also an assertion difference between array('a, b, c') and array('a', 'b', 'c') is not that easy to spot. Maybe adding an assertion about the number of rows would make the distinction easier to spot.

Risha’s picture

There is a same problem for drupal 7 views module, how could this patch be applied to the views version for drupal 7?

geertvd’s picture

I removed the second view and changed the group_rows value in the test.
I also moved both scenarios in 1 test method and changed the way I'm handling assertions a bit.

geertvd’s picture

Status: Needs work » Needs review

The last submitted patch, 29: 2397495-29-tests.patch, failed testing.

dawehner’s picture

  1. +++ b/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php
    @@ -0,0 +1,95 @@
    +    // test grouped rows.
    ...
    +    // change the group_rows checkbox to false.
    ...
    +    // test ungrouped rows.
    

    Let's start with a upper character :(

  2. +++ b/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php
    @@ -0,0 +1,95 @@
    +    $this->assertEqual($view->field[$this->fieldName]->advancedRender($view->result[0]), 'a, b, c');
    ...
    +    $this->assertEqual($view->field[$this->fieldName]->advancedRender($view->result[0]), 'a');
    +    $this->assertEqual($view->field[$this->fieldName]->advancedRender($view->result[1]), 'b');
    +    $this->assertEqual($view->field[$this->fieldName]->advancedRender($view->result[2]), 'c');
    

    This is indeed way more readable!

geertvd’s picture

Start comments with uppercase

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

@geertvd
Feel free to include interdiffs (see https://www.drupal.org/documentation/git/interdiff ) in more core patches you do :)

The last submitted patch, 33: 2397495-33-tests.patch, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

That's turned out really nice - thanks @geertvd. Committed 38b7427 and pushed to 8.0.x. Thanks!

Thank you for adding the beta evaluation to the summary.

diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php
index c17a359..6788677 100644
--- a/core/modules/views/src/Plugin/views/field/Field.php
+++ b/core/modules/views/src/Plugin/views/field/Field.php
@@ -783,7 +783,6 @@ public function getItems(ResultRow $values) {
    *
    * @param \Drupal\views\ResultRow $values
    *   The result row object containing the values.
-   *
    * @param \Drupal\Core\Entity\EntityInterface $entity
    *   The entity to be processed.
    *

On commit I removed the new line between the @param docs since it shouldn't be there.

  • alexpott committed 38b7427 on 8.0.x
    Issue #2397495 by geertvd, jhedstrom: Disabling 'Display all values in...

Status: Fixed » Closed (fixed)

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

ojchris’s picture

Interesting that this bug has returned in Drupal 8.