Add description en tableformater
Add new code in line 27 and 31
change file: TableFormatter.php
<?php
namespace Drupal\file\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Plugin implementation of the 'file_table' formatter.
*
* @FieldFormatter(
* id = "file_table",
* label = @Translation("Table of files"),
* field_types = {
* "file"
* }
* )
*/
class TableFormatter extends FileFormatterBase {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
if ($files = $this->getEntitiesToView($items, $langcode)) {
$header = array(t('Attachment'), t('Size'));
$rows = array();
foreach ($files as $delta => $file) {
$item = $file->_referringItem; #new Code
$rows[] = array(
array(
'data' => array(
'#theme' => 'file_link',
'#file' => $file,
'#description'=> $item->description, #new Code
'#cache' => array(
'tags' => $file->getCacheTags(),
),
),
),
array('data' => format_size($file->getSize())),
);
}
$elements[0] = array();
if (!empty($rows)) {
$elements[0] = array(
'#theme' => 'table__file_formatter_table',
'#header' => $header,
'#rows' => $rows,
);
}
}
return $elements;
}
}
?>
Comments
Comment #2
kapil.ropalekar commentedAttached is the patch to add the Description in TableFormatter as per suggested changes.
Kindly review. Thanks !
Comment #3
kapil.ropalekar commentedComment #4
mstrelan commented