You are here

class CommentedEntity in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/comment/src/Plugin/views/field/CommentedEntity.php \Drupal\comment\Plugin\views\field\CommentedEntity
  2. 9 core/modules/comment/src/Plugin/views/field/CommentedEntity.php \Drupal\comment\Plugin\views\field\CommentedEntity

Views field display for commented entity.

Plugin annotation

@ViewsField("commented_entity");

Hierarchy

  • class \Drupal\comment\Plugin\views\field\CommentedEntity extends \Drupal\views\Plugin\views\field\EntityField

Expanded class hierarchy of CommentedEntity

File

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

Namespace

Drupal\comment\Plugin\views\field
View source
class CommentedEntity extends EntityField {

  /**
   * Array of entities that has comments.
   *
   * We use this to load all the commented entities of same entity type at once
   * to the EntityStorageController static cache.
   *
   * @var array
   */
  protected $loadedCommentedEntities = [];

  /**
   * {@inheritdoc}
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommentedEntity::$loadedCommentedEntities protected property Array of entities that has comments.
CommentedEntity::getItems public function