Plugin implementation of the 'file_default' formatter.
@FieldFormatter(
id = "file_default",
module = "file",
label = @Translation("Generic file"),
field_types = {
"file"
}
)
Expanded class hierarchy of GenericFileFormatter
class GenericFileFormatter extends FormatterBase {
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$elements = array();
foreach ($items as $delta => $item) {
$elements[$delta] = array(
'#theme' => 'file_link',
'#file' => file_load($item['fid']),
'#description' => $item['description'],
);
}
return $elements;
}
}