CommentedEntity.php in Drupal 9
File
core/modules/comment/src/Plugin/views/field/CommentedEntity.php
View source
<?php
namespace Drupal\comment\Plugin\views\field;
use Drupal\views\Plugin\views\field\EntityField;
use Drupal\views\ResultRow;
class CommentedEntity extends EntityField {
protected $loadedCommentedEntities = [];
public function getItems(ResultRow $values) {
if (empty($this->loadedCommentedEntities)) {
$result = $this->view->result;
$entity_ids_per_type = [];
foreach ($result as $value) {
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);
}
}