$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; } /** * {@inheritdoc} */ public static function isApplicable(FieldDefinitionInterface $field_definition) { return $field_definition->getName() === 'name' && $field_definition->getTargetEntityTypeId() === 'comment'; } }