When using the DownloadFile field formatter on a full node view, the labels for empty fields are not hidden...which is the default Drupal behavior.

I tested this by changing the display format from DownloadFile to Generic File. With the Generic File formatter, the label for empty fields does not display. With the DownloadFile formatter, the label does display.

I've been looking for a solution, but haven't nailed it yet. I'll post back if I find one.

CommentFileSizeAuthor
#11 1436052-hidden-labels.patch1.99 KBjnettik

Comments

amir simantov’s picture

Same here.

sachbearbeiter’s picture

same problem

sachbearbeiter’s picture

Priority: Normal » Major

it's not possible to handle (hide) empty fields (drupal basics) -> major

Bernsch’s picture

Same here! how can we solve it?
It would be good to fix it - because the other it works...

xMATTx’s picture

Assigned: Unassigned » xMATTx
Status: Active » Needs review

Hey,

Sorry for the delay, can you try this patch?

I have not had time to put myself in Git.

Replace this function in download_file.module:

function download_file_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();

  switch ($display['type']) {
    case 'direct_download':
      $element[0] = array(
        '#theme' => 'download_file_formatter_direct_download',
        '#items' => $items
      );
      break;

    case 'direct_download_icon':
      $element[0] = array(
        '#theme' => 'download_file_formatter_direct_download_icon',
        '#items' => $items
      );
      break;

    case 'direct_download_accessible':
      $element[0] = array(
        '#theme' => 'download_file_formatter_direct_download_accessible',
        '#items' => $items
      );
      break;

    case 'direct_download_accessible_icon':
      $element[0] = array(
        '#theme' => 'download_file_formatter_direct_download_accessible_icon',
        '#items' => $items
      );
      break;
  }

  return $element;
}

with this one:

function download_file_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  
  if ($items) {
    switch ($display['type']) {
      case 'direct_download':
        $element[0] = array(
          '#theme' => 'download_file_formatter_direct_download',
          '#items' => $items
        );
        break;

      case 'direct_download_icon':
        $element[0] = array(
          '#theme' => 'download_file_formatter_direct_download_icon',
          '#items' => $items
        );
        break;

      case 'direct_download_accessible':
        $element[0] = array(
          '#theme' => 'download_file_formatter_direct_download_accessible',
          '#items' => $items
        );
        break;

      case 'direct_download_accessible_icon':
        $element[0] = array(
          '#theme' => 'download_file_formatter_direct_download_accessible_icon',
          '#items' => $items
        );
        break;
    }
  }

  return $element;
}

Thank you

Matthieu

Bernsch’s picture

I've tested the code and it works for me!
thank you very much, Matthieu!

xMATTx’s picture

I am still sorry for the delay.

I'll try to put myself in Git to generate a patch.

Matthieu

Bernsch’s picture

Status: Needs review » Fixed
stan turyn’s picture

Status: Fixed » Needs work

Why has this been marked 'fixed' if there have been no commits in over a year? Clearly the solution that's been posted here is yet to be commited.

Bernsch’s picture

Status: Needs work » Needs review

@xMATTx
Can you make a patch from #5. Then we can set the contribution as RTBC.
Thanks!

jnettik’s picture

StatusFileSize
new1.99 KB

Here are the changes in #5 as a patch. The code itself does work for me.

  • neerajskydiver committed 9d35d2a on 7.x-2.x-dev
    Issue #1436052 by poieo: Fixed Field Formatter Doesn't Allow for Empty...
Hogeboom’s picture

Issue summary: View changes

Works great, thank you!

neerajskydiver’s picture

Status: Needs review » Fixed

code committed & changing the status to fixed.

Status: Fixed » Closed (fixed)

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