One of my fields was empty numeric field with 0 value and I've noticed that the Table Views Style will not display it even when there is no empty value override or anything like that.

I found out the issue was in the template_preprocess_views_view_table preprocess function which used empty() to assess if the field was empty or not which obviously don't apply to 0. I've attached a simple patch that works for me though the second part of the if statement may require additional rewriting.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug
Unfrozen changes Unfrozen because it only fixes a bug/regression in Views

Comments

Status: Needs review » Needs work

The last submitted patch, views.theme_.inc-zero.patch, failed testing.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new553 bytes
dawehner’s picture

Version: 8.0-alpha10 » 8.x-dev
Issue tags: +VDC

Thank you for the patch.

Moving to DEV as everything else is kinda pointless :) I wonder whether you could also write a patch.

StyleTableTest already has some tests which you can probably extend.

Anonymous’s picture

I'd love to but I haven't written one yet so I'd leave that to someone who knows what he's doing.

jhedstrom’s picture

Issue summary: View changes
StatusFileSize
new1.93 KB
new2.64 KB

This adds a test that illustrates the bug, and the fix from above.

I also added a beta phase evaluation.

Status: Needs review » Needs work

The last submitted patch, 5: views-table-display-2244507-05.patch, failed testing.

The last submitted patch, 5: views-table-display-2244507-05-TEST-ONLY.patch, failed testing.

Status: Needs work » Needs review

The last submitted patch, 5: views-table-display-2244507-05-TEST-ONLY.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: views-table-display-2244507-05.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new2.31 KB
new3.02 KB
new2.4 KB

Those xpath tests were passing locally. I've updated them to be a bit more verbose to see if that makes the testbot happy.

Status: Needs review » Needs work

The last submitted patch, 12: views-table-display-2244507-12.patch, failed testing.

The last submitted patch, 12: views-table-display-2244507-12-TEST-ONLY.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new1.99 KB
new2.7 KB
new2.42 KB

Ok. This time, GREEN!

jhedstrom’s picture

The last submitted patch, 15: views-table-display-2244507-15-TEST-ONLY.patch, failed testing.

jhedstrom’s picture

I marked #2171497: Table fields with the integer value zero are not displayed. as a duplicate. Both had a patch, the tests here also test the 'treat 0 as empty' option though.

dawehner’s picture

+++ b/core/modules/views/views.theme.inc
@@ -573,7 +573,7 @@ function template_preprocess_views_view_table(&$variables) {
-        if (!empty($field_output) && empty($column_reference['content'])) {
+        if ((string) $field_output !== '' && empty($column_reference['content'])) {

Just curios, don't we have to take "empty_zero" on the field settings into account here?

jhedstrom’s picture

Hmm, the test I added covers 'empty zero'. I think the reason the code in #19 doesn't need to worry about the 'empty zero' setting is that just below, there is a empty() check. The full code:

       // Only bother with separators and stuff if the field shows up.
        if ((string) $field_output !== '' && empty($column_reference['content'])) {
          // Place the field into the column, along with an optional separator.
          if (!empty($column_reference['content'])) {
            if (!empty($options['info'][$column]['separator'])) {
              $safe_content = SafeMarkup::escape($column_reference['content']);
              $safe_separator = Xss::filterAdmin($options['info'][$column]['separator']);
              $column_reference['content'] = SafeMarkup::set($safe_content . $safe_separator);
            }
          }
          else {
            $column_reference['content'] = '';
          }
          $safe_content = SafeMarkup::escape($column_reference['content']);
          $safe_field_output = SafeMarkup::escape($field_output);
          $column_reference['content'] = SafeMarkup::set($safe_content . $safe_field_output);
        }
lendude’s picture

StatusFileSize
new2.64 KB

Patch in #15 needed a reroll. This is that reroll.

Looks good to go to me though.

On 'empty zero': isn't that handled by the field handler? It is in Drupal\views\Plugin\views\field\Numeric anyway. So I'd say this level of the theme layer doesn't need to worry about it, let the field handler worry about it.

Status: Needs review » Needs work

The last submitted patch, 21: views-table-display-2244507-21.patch, failed testing.

lendude’s picture

Issue tags: +Needs reroll

Not surprisingly, this doesn't apply anymore.

lendude’s picture

Status: Needs work » Closed (duplicate)
Issue tags: -Needs reroll