public function EntityReferenceTaxonomyTermRssFormatter::viewElements in Drupal 10
Same name and namespace in other branches
- 8 core/modules/taxonomy/src/Plugin/Field/FieldFormatter/EntityReferenceTaxonomyTermRssFormatter.php \Drupal\taxonomy\Plugin\Field\FieldFormatter\EntityReferenceTaxonomyTermRssFormatter::viewElements()
- 9 core/modules/taxonomy/src/Plugin/Field/FieldFormatter/EntityReferenceTaxonomyTermRssFormatter.php \Drupal\taxonomy\Plugin\Field\FieldFormatter\EntityReferenceTaxonomyTermRssFormatter::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 FormatterInterface::viewElements
File
- core/
modules/ taxonomy/ src/ Plugin/ Field/ FieldFormatter/ EntityReferenceTaxonomyTermRssFormatter.php, line 27
Class
- EntityReferenceTaxonomyTermRssFormatter
- Plugin implementation of the 'entity reference taxonomy term RSS' formatter.
Namespace
Drupal\taxonomy\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$parent_entity = $items
->getEntity();
$elements = [];
foreach ($this
->getEntitiesToView($items, $langcode) as $entity) {
$parent_entity->rss_elements[] = [
'key' => 'category',
'value' => $entity
->label(),
'attributes' => [
'domain' => $entity
->id() ? Url::fromRoute('entity.taxonomy_term.canonical', [
'taxonomy_term' => $entity
->id(),
], [
'absolute' => TRUE,
])
->toString() : '',
],
];
}
return $elements;
}