Issue #2020677 by yched: file_field_prepare_view() should not delete items.

8.0.x
Alex Pott 2013-06-18 09:27:54 +02:00
parent 0e8571d150
commit 2635b665fd
5 changed files with 40 additions and 37 deletions

View File

@ -191,27 +191,22 @@ function file_field_prepare_view($entity_type, $entities, $field, $instances, $l
$fids = array();
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => $item) {
if (!file_field_displayed($item, $field)) {
unset($items[$id][$delta]);
}
elseif (!empty($item['fid'])) {
if (file_field_displayed($item, $field) && !empty($item['fid'])) {
// Load the files from the files table.
$fids[] = $item['fid'];
}
}
// Ensure consecutive deltas.
$items[$id] = array_values($items[$id]);
}
$files = file_load_multiple($fids);
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => $item) {
// If the file does not exist, mark the entire item as empty.
if (empty($item['fid']) || !isset($files[$item['fid']])) {
$items[$id][$delta] = NULL;
}
else {
$items[$id][$delta]['entity'] = $files[$item['fid']];
if ($fids) {
$files = file_load_multiple($fids);
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => $item) {
// If the file does not exist, mark the entire item as empty.
if (!empty($item['fid'])) {
$items[$id][$delta]['entity'] = isset($files[$item['fid']]) ? $files[$item['fid']] : NULL;
}
}
}
}
@ -854,10 +849,12 @@ function theme_file_formatter_table($variables) {
$header = array(t('Attachment'), t('Size'));
$rows = array();
foreach ($variables['items'] as $delta => $item) {
$rows[] = array(
theme('file_link', array('file' => $item['entity'])),
format_size($item['entity']->getSize()),
);
if ($item['display'] && $item['entity']) {
$rows[] = array(
theme('file_link', array('file' => $item['entity'])),
format_size($item['entity']->getSize()),
);
}
}
return empty($rows) ? '' : theme('table', array('header' => $header, 'rows' => $rows));

View File

@ -33,11 +33,13 @@ class GenericFileFormatter extends FormatterBase {
$elements = array();
foreach ($items as $delta => $item) {
$elements[$delta] = array(
'#theme' => 'file_link',
'#file' => $item['entity'],
'#description' => $item['description'],
);
if ($item['display'] && $item['entity']) {
$elements[$delta] = array(
'#theme' => 'file_link',
'#file' => $item['entity'],
'#description' => $item['description'],
);
}
}
return $elements;

View File

@ -34,7 +34,7 @@ class RSSEnclosureFormatter extends FormatterBase {
// Add the first file as an enclosure to the RSS item. RSS allows only one
// enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure
foreach ($items as $item) {
if ($item['display']) {
if ($item['display'] && $item['entity']) {
$file = $item['entity'];
$entity->rss_elements[] = array(
'key' => 'enclosure',

View File

@ -33,7 +33,9 @@ class UrlPlainFormatter extends FormatterBase {
$elements = array();
foreach ($items as $delta => $item) {
$elements[$delta] = array('#markup' => empty($item['entity']) ? '' : file_create_url($item['entity']->getFileUri()));
if ($item['display'] && $item['entity']) {
$elements[$delta] = array('#markup' => empty($item['entity']) ? '' : file_create_url($item['entity']->getFileUri()));
}
}
return $elements;

View File

@ -107,19 +107,21 @@ class ImageFormatter extends FormatterBase {
$image_style_setting = $this->getSetting('image_style');
foreach ($items as $delta => $item) {
if (isset($link_file)) {
$image_uri = $item['entity']->getFileUri();
$uri = array(
'path' => file_create_url($image_uri),
'options' => array(),
if ($item['entity']) {
if (isset($link_file)) {
$image_uri = $item['entity']->getFileUri();
$uri = array(
'path' => file_create_url($image_uri),
'options' => array(),
);
}
$elements[$delta] = array(
'#theme' => 'image_formatter',
'#item' => $item,
'#image_style' => $image_style_setting,
'#path' => isset($uri) ? $uri : '',
);
}
$elements[$delta] = array(
'#theme' => 'image_formatter',
'#item' => $item,
'#image_style' => $image_style_setting,
'#path' => isset($uri) ? $uri : '',
);
}
return $elements;