class TableFormatter
Same name and namespace in other branches
- 10 core/modules/file/src/Plugin/Field/FieldFormatter/TableFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\TableFormatter
- 11.x core/modules/file/src/Plugin/Field/FieldFormatter/TableFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\TableFormatter
- 8.9.x core/modules/file/src/Plugin/Field/FieldFormatter/TableFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\TableFormatter
- main core/modules/file/src/Plugin/Field/FieldFormatter/TableFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\TableFormatter
Plugin implementation of the 'file_table' formatter.
Plugin annotation
@FieldFormatter(
id = "file_table",
label = @Translation("Table of files"),
field_types = {
"file"
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Field\FormatterBase implements \Drupal\Core\Field\FormatterInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface extends \Drupal\Core\Field\PluginSettingsBase
- class \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase extends \Drupal\Core\Field\FormatterBase
- class \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase extends \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase
- class \Drupal\file\Plugin\Field\FieldFormatter\DescriptionAwareFileFormatterBase extends \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase
- class \Drupal\file\Plugin\Field\FieldFormatter\TableFormatter extends \Drupal\file\Plugin\Field\FieldFormatter\DescriptionAwareFileFormatterBase
- class \Drupal\file\Plugin\Field\FieldFormatter\DescriptionAwareFileFormatterBase extends \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase
- class \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase extends \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase
- class \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase extends \Drupal\Core\Field\FormatterBase
- class \Drupal\Core\Field\FormatterBase implements \Drupal\Core\Field\FormatterInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface extends \Drupal\Core\Field\PluginSettingsBase
- class \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of TableFormatter
File
-
core/
modules/ file/ src/ Plugin/ Field/ FieldFormatter/ TableFormatter.php, line 18
Namespace
Drupal\file\Plugin\Field\FieldFormatterView source
class TableFormatter extends DescriptionAwareFileFormatterBase {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
if ($files = $this->getEntitiesToView($items, $langcode)) {
$header = [
$this->t('Attachment'),
$this->t('Size'),
];
$rows = [];
foreach ($files as $file) {
$item = $file->_referringItem;
$rows[] = [
[
'data' => [
'#theme' => 'file_link',
'#file' => $file,
'#description' => $this->getSetting('use_description_as_link_text') ? $item->description : NULL,
'#cache' => [
'tags' => $file->getCacheTags(),
],
],
],
[
'data' => format_size($file->getSize()),
],
];
}
$elements[0] = [];
if (!empty($rows)) {
$elements[0] = [
'#theme' => 'table__file_formatter_table',
'#header' => $header,
'#rows' => $rows,
];
}
}
return $elements;
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.