function AuthorNameFormatter::viewElements
Same name in other branches
- 9 core/modules/comment/src/Plugin/Field/FieldFormatter/AuthorNameFormatter.php \Drupal\comment\Plugin\Field\FieldFormatter\AuthorNameFormatter::viewElements()
- 10 core/modules/comment/src/Plugin/Field/FieldFormatter/AuthorNameFormatter.php \Drupal\comment\Plugin\Field\FieldFormatter\AuthorNameFormatter::viewElements()
- 11.x core/modules/comment/src/Plugin/Field/FieldFormatter/AuthorNameFormatter.php \Drupal\comment\Plugin\Field\FieldFormatter\AuthorNameFormatter::viewElements()
Overrides FormatterInterface::viewElements
File
-
core/
modules/ comment/ src/ Plugin/ Field/ FieldFormatter/ AuthorNameFormatter.php, line 26
Class
- AuthorNameFormatter
- Plugin implementation of the 'comment_username' formatter.
Namespace
Drupal\comment\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
/** @var $comment \Drupal\comment\CommentInterface */
$comment = $item->getEntity();
$account = $comment->getOwner();
$elements[$delta] = [
'#theme' => 'username',
'#account' => $account,
'#cache' => [
'tags' => $account->getCacheTags() + $comment->getCacheTags(),
],
];
}
return $elements;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.