Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 19 |
GenericFileFormatter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 19 |
viewElements | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 19 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\file\Plugin\Field\FieldFormatter\GenericFileFormatter. | |
*/ | |
namespace Drupal\file\Plugin\Field\FieldFormatter; | |
use Drupal\Core\Field\FieldItemListInterface; | |
/** | |
* Plugin implementation of the 'file_default' formatter. | |
* | |
* @FieldFormatter( | |
* id = "file_default", | |
* label = @Translation("Generic file"), | |
* field_types = { | |
* "file" | |
* } | |
* ) | |
*/ | |
class GenericFileFormatter extends FileFormatterBase { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function viewElements(FieldItemListInterface $items, $langcode) { | |
$elements = array(); | |
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) { | |
$item = $file->_referringItem; | |
$elements[$delta] = array( | |
'#theme' => 'file_link', | |
'#file' => $file, | |
'#description' => $item->description, | |
'#cache' => array( | |
'tags' => $file->getCacheTags(), | |
), | |
); | |
// Pass field item attributes to the theme function. | |
if (isset($item->_attributes)) { | |
$elements[$delta] += array('#attributes' => array()); | |
$elements[$delta]['#attributes'] += $item->_attributes; | |
// Unset field item attributes since they have been included in the | |
// formatter output and should not be rendered in the field template. | |
unset($item->_attributes); | |
} | |
} | |
return $elements; | |
} | |
} |