1. Create a content type with an integer field
2. Create a node of this type with field value 0 (zero)
3. Create a view for this content type, with fields "Title" and the integer field
4. Set the format to "Table"

The preview will only show the title, the integer field is empty.

Selecting other formats (Grid, HTML list, etc.) will correctly display the integer field as 0.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug, because you want to be able to see "0" as output of a field.
Issue priority Normal, not all views use 0 as output. For numeric kind of data though its really common
Disruption None, it works again like d7/d6

Comments

pieterjanput’s picture

Status: Active » Needs review
Issue tags: +Drupalaton 2015
StatusFileSize
new672 bytes

empty() returns TRUE for 0, therefore this wasn't working. Added extra check for numeric.

borisson_’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
StatusFileSize
new19.08 KB
new20.42 KB

The attached patch solves the issue, I've attached screenshots of before/after applying the patch.

I think the is_numeric call is a good solution to make sure this doesn't happen again. I think this needs a test though, this can go in \Drupal\views\Tests\Plugin\StyleTableTest..

borisson_’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.45 KB
new2.11 KB

Attached patch has a test that proves this fix is correct. Test-only should fail.

Status: Needs review » Needs work

The last submitted patch, 3: zero_value_not_shown_in-2543132-3.patch, failed testing.

The last submitted patch, 3: zero_value_not_shown_in-2543132-3-test-only.patch, failed testing.

dazz’s picture

Status: Needs work » Needs review
StatusFileSize
new582 bytes
new647 bytes

Instead of checking empty or numeric, just check if string is empty.
Still needs tests.

borisson_’s picture

StatusFileSize
new1.55 KB
new1.95 KB

Readded the test I added in #3. Removed the extra person from ViewTestData::dataSet, this should resolve all the extra failures in #3.

jeroent’s picture

Version: 8.0.0-beta13 » 8.0.x-dev
dawehner’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/views/views.theme.inc
@@ -582,7 +582,7 @@ function template_preprocess_views_view_table(&$variables) {
+        if (trim($field_output) != "") {

Feel free to correct the "" to ''

jeroent’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.95 KB
new557 bytes

Replaced "" with ''.

Patch attached.

jeroent’s picture

Status: Needs review » Reviewed & tested by the community

Setting back to RTBC as I only replaced the quotation marks.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: zero_value_not_shown_in-2543132-10.patch, failed testing.

jeroent’s picture

Status: Needs work » Reviewed & tested by the community

I think these are random test failures. Back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed b399f75 and pushed to 8.0.x. Thanks!

  • alexpott committed b399f75 on
    Issue #2543132 by borisson_, JeroenT, dazz, PieterJanPut, gaele: Zero...

Status: Fixed » Closed (fixed)

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

delacosta456’s picture

hi
Please can somebody help us solve this in drupal 7

cilefen’s picture

delacosta456: Find or open an issue in the Views project.