public function EntityReferencePathFormatter::viewElements in REST Views 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldFormatter/EntityReferencePathFormatter.php \Drupal\rest_views\Plugin\Field\FieldFormatter\EntityReferencePathFormatter::viewElements()
Builds a renderable array for a field value.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: The language that should be used to render the field.
Return value
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
Overrides LinkFormatter::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ EntityReferencePathFormatter.php, line 26
Class
- EntityReferencePathFormatter
- Plugin implementation of the 'entity_path' formatter.
Namespace
Drupal\rest_views\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) : array {
$elements = [];
foreach ($items as $delta => $item) {
/** @var \Drupal\Core\Url $url */
$url = $item->entity
->toUrl();
$elements[$delta] = [
'#type' => 'data',
'#data' => SerializedData::create($url
->toString()),
];
}
return $elements;
}