I added a field of type File to a content type to which I allowed multiple values and the Enable Display field property. When I upload files to this field and check various files to display, the results differ (seemingly randomly but for a pattern always identically) from what I set with the checkboxes. Most notably it seems to be impossible to hide all files while checking all boxes seem to result in properly listing all of them.

I produced this with a Drupal installation having Views, Panels, CTools and Token external modules installed, I thought these won't affect this. If necessary I can experiment some more with it.

Comments

Bob K’s picture

Function file_field_prepare_view() in file.field.inc scans an array of files available for display and deletes the unwanted items from that array. The statement at line 207 is meant to leave the array in a tidy set of consecutive ([0],[1],[2]...) elements, but that should wait until after the foreach($items...) loop is finished.

Here's how it should look:

function file_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
  // Remove files specified to not be displayed.
  foreach ($entities as $id => $entity) {
    foreach ($items[$id] as $delta => $item) {
      if (!file_field_displayed($item, $field)) {
        unset($items[$id][$delta]);
      }
    }
    // Ensure consecutive deltas.
    $items[$id] = array_values($items[$id]);
  }
}
jubatian’s picture

Tested, works! Thanks, problem solved I guess :)

andypost’s picture

Version: 7.0 » 8.x-dev
Component: field system » file.module
Priority: Minor » Major
Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new853 bytes

Suppose this should fix but needs tests

Status: Needs review » Needs work

The last submitted patch, 1140262-filefield-display.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new732 bytes

This patch actually fixes bug. But this points that php docs errors? at http://php.net/manual/en/language.types.array.php

Edit using php PHP 5.2.17 debian

andypost’s picture

Version: 8.x-dev » 7.0
Status: Needs review » Closed (duplicate)
Issue tags: -Needs tests