I will propose a patch that hides a field (ie no new line is printed) if it is empty and if the "Hide if empty" checkbox is checked in the field configuration.

CommentFileSizeAuthor
#1 2032863-hide_fields-1.patch437 bytesguillaumev
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

guillaumev’s picture

Status: Active » Needs review
FileSize
437 bytes

Here is the patch.

killua99’s picture

+++ b/views_pdf_template.php
@@ -394,7 +394,7 @@ class PdfTemplate extends FPDI {
+    if (!empty($view->field[$key]->options['exclude']) || (empty($content) && $view->field[$key]->options['hide_empty'])) {

The $content means the whole content view? the row? or just the field?

I'm lost in this part.

guillaumev’s picture

It means just the field.

The expected behavior, in my opinion, is that when you check "Hide if empty" in a field configuration, whenever the field is empty, it shouldn't print anything (ie not even a new line), which wasn't the case so far.

killua99’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

Works fine, as you say. well done!

Info for the maintainer:
Exist a patch to handle this issues and others. Please see #2032189-4: Multiple issue fixing in a single patch: Multiple issue fixing in a single patch and review others issues patch.

This is RTBC, and ready to apply.

killua99’s picture

Priority: Major » Normal
Status: Reviewed & tested by the community » Fixed

Thanks guillaumev committed

Status: Fixed » Closed (fixed)

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

attisan’s picture

Issue summary: View changes

my solution:

-    if (!empty($view->field[$key]->options['exclude'])) {
+    if (!empty($view->field[$key]->options['exclude']) || (empty($row->_field_data['nid']['entity']->$key) && $view->field[$key]->options['hide_empty'])) {

works for fieldCollections too.

greets

killua99’s picture

Status: Closed (fixed) » Needs work

We need to take a look at those lines.

  • guillaumev authored 57d2bae on 8.x-1.x
    Issue #2032863 by guillaumev: Added Hide fields if they are empty.
    
killua99’s picture

Status: Needs work » Closed (outdated)