Commit 2635b665 authored by alexpott's avatar alexpott

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

parent 0e8571d1
......@@ -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));
......
......@@ -33,11 +33,13 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
$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;
......
......@@ -34,7 +34,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
// 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',
......
......@@ -33,7 +33,9 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
$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;
......
......@@ -107,19 +107,21 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
$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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment