Issue #2090619 by yched, smiletrl: Move file visibility check to the FileItem class.
parent
88ca8e967b
commit
a40485a5ed
|
@ -523,15 +523,15 @@ function theme_file_formatter_table($variables) {
|
|||
$header = array(t('Attachment'), t('Size'));
|
||||
$rows = array();
|
||||
foreach ($variables['items'] as $delta => $item) {
|
||||
if ($item['display'] && $item['entity']) {
|
||||
if ($item->isDisplayed() && $item->entity) {
|
||||
$rows[] = array(
|
||||
array(
|
||||
'data' => array(
|
||||
'#theme' => 'file_link',
|
||||
'#file' => $item['entity'],
|
||||
'#file' => $item->entity,
|
||||
),
|
||||
),
|
||||
format_size($item['entity']->getSize()),
|
||||
format_size($item->entity->getSize()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,4 +311,17 @@ class FileItem extends EntityReferenceItem implements ConfigFieldItemInterface {
|
|||
return $validators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an item should be displayed when rendering the field.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the item should be displayed, FALSE if not.
|
||||
*/
|
||||
public function isDisplayed() {
|
||||
if ($this->getFieldSetting('display_field')) {
|
||||
return (bool) $this->display;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ abstract class FileFormatterBase extends FormatterBase {
|
|||
$fids = array();
|
||||
foreach ($entities_items as $items) {
|
||||
foreach ($items as $item) {
|
||||
if ($this->isDisplayed($item) && !empty($item->target_id)) {
|
||||
if ($item->isDisplayed() && !empty($item->target_id)) {
|
||||
// Load the files from the files table.
|
||||
$fids[] = $item->target_id;
|
||||
}
|
||||
|
@ -42,23 +42,4 @@ abstract class FileFormatterBase extends FormatterBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a file should be displayed when outputting field content.
|
||||
*
|
||||
* @param $item
|
||||
* A field item array.
|
||||
* @param $field
|
||||
* A field array.
|
||||
*
|
||||
* @return
|
||||
* Boolean TRUE if the file will be displayed, FALSE if the file is hidden.
|
||||
*/
|
||||
protected function isDisplayed($item) {
|
||||
$settings = $this->getFieldSettings();
|
||||
if (!empty($settings['display_field'])) {
|
||||
return (bool) $item->display;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class GenericFileFormatter extends FileFormatterBase {
|
|||
$elements = array();
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
if ($item->display && $item->entity) {
|
||||
if ($item->isDisplayed() && $item->entity) {
|
||||
$elements[$delta] = array(
|
||||
'#theme' => 'file_link',
|
||||
'#file' => $item->entity,
|
||||
|
|
|
@ -32,7 +32,7 @@ class RSSEnclosureFormatter extends FileFormatterBase {
|
|||
// 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 && $item->entity) {
|
||||
if ($item->isDisplayed() && $item->entity) {
|
||||
$file = $item->entity;
|
||||
$entity->rss_elements[] = array(
|
||||
'key' => 'enclosure',
|
||||
|
|
|
@ -34,7 +34,7 @@ class TableFormatter extends FileFormatterBase {
|
|||
// Display all values in a single element.
|
||||
$elements[0] = array(
|
||||
'#theme' => 'file_formatter_table',
|
||||
'#items' => $items->getValue(TRUE),
|
||||
'#items' => $items,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class UrlPlainFormatter extends FileFormatterBase {
|
|||
$elements = array();
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
if ($item->display && $item->entity) {
|
||||
if ($item->isDisplayed() && $item->entity) {
|
||||
$elements[$delta] = array('#markup' => empty($item->entity) ? '' : file_create_url($item->entity->getFileUri()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -318,4 +318,12 @@ class ImageItem extends FileItem {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isDisplayed() {
|
||||
// Image items do not have per-item visibility settings.
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue