function AuthorFormatter::viewElements
Same name in other branches
- 9 core/modules/user/src/Plugin/Field/FieldFormatter/AuthorFormatter.php \Drupal\user\Plugin\Field\FieldFormatter\AuthorFormatter::viewElements()
- 8.9.x core/modules/user/src/Plugin/Field/FieldFormatter/AuthorFormatter.php \Drupal\user\Plugin\Field\FieldFormatter\AuthorFormatter::viewElements()
- 10 core/modules/user/src/Plugin/Field/FieldFormatter/AuthorFormatter.php \Drupal\user\Plugin\Field\FieldFormatter\AuthorFormatter::viewElements()
Overrides FormatterInterface::viewElements
File
-
core/
modules/ user/ src/ Plugin/ Field/ FieldFormatter/ AuthorFormatter.php, line 28
Class
- AuthorFormatter
- Plugin implementation of the 'author' formatter.
Namespace
Drupal\user\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
$elements[$delta] = [
'#theme' => 'username',
'#account' => $entity,
'#link_options' => [
'attributes' => [
'rel' => 'author',
],
],
'#cache' => [
'tags' => $entity->getCacheTags(),
],
];
}
return $elements;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.