Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 11 |
UrlPlainFormatter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 11 |
viewElements | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 11 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\file\Plugin\Field\FieldFormatter\UrlPlainFormatter. | |
*/ | |
namespace Drupal\file\Plugin\Field\FieldFormatter; | |
use Drupal\Core\Field\FieldItemListInterface; | |
/** | |
* Plugin implementation of the 'file_url_plain' formatter. | |
* | |
* @FieldFormatter( | |
* id = "file_url_plain", | |
* label = @Translation("URL to file"), | |
* field_types = { | |
* "file" | |
* } | |
* ) | |
*/ | |
class UrlPlainFormatter extends FileFormatterBase { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function viewElements(FieldItemListInterface $items, $langcode) { | |
$elements = array(); | |
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) { | |
$elements[$delta] = array( | |
'#markup' => file_url_transform_relative(file_create_url($file->getFileUri())), | |
'#cache' => array( | |
'tags' => $file->getCacheTags(), | |
), | |
); | |
} | |
return $elements; | |
} | |
} |