Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CommentedEntity.php

function CommentedEntity::getItems

Overrides EntityField::getItems

File

core/modules/comment/src/Plugin/views/field/CommentedEntity.php, line 28

Class

CommentedEntity
Views field display for commented entity.

Namespace

Drupal\comment\Plugin\views\field

Code

public function getItems(ResultRow $values) {
    if (empty($this->loadedCommentedEntities)) {
        $result = $this->view->result;
        $entity_ids_per_type = [];
        foreach ($result as $value) {
            
            /** @var \Drupal\comment\CommentInterface $comment */
            if ($comment = $this->getEntity($value)) {
                $entity_ids_per_type[$comment->getCommentedEntityTypeId()][] = $comment->getCommentedEntityId();
            }
        }
        foreach ($entity_ids_per_type as $type => $ids) {
            $this->loadedCommentedEntities[$type] = $this->entityTypeManager
                ->getStorage($type)
                ->loadMultiple($ids);
        }
    }
    return parent::getItems($values);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal