public function ElasticsearchViewsEntity::preRender in Elasticsearch Connector 8.2
Same name and namespace in other branches
- 8.7 modules/elasticsearch_connector_views/src/Plugin/views/field/ElasticsearchViewsEntity.php \Drupal\elasticsearch_connector_views\Plugin\views\field\ElasticsearchViewsEntity::preRender()
- 8.5 modules/elasticsearch_connector_views/src/Plugin/views/field/ElasticsearchViewsEntity.php \Drupal\elasticsearch_connector_views\Plugin\views\field\ElasticsearchViewsEntity::preRender()
- 8.6 modules/elasticsearch_connector_views/src/Plugin/views/field/ElasticsearchViewsEntity.php \Drupal\elasticsearch_connector_views\Plugin\views\field\ElasticsearchViewsEntity::preRender()
Runs before any fields are rendered.
This gives the handlers some time to set up before any handler has been rendered.
Parameters
\Drupal\views\ResultRow[] $values: An array of all ResultRow objects returned from the query.
Overrides FieldPluginBase::preRender
File
- modules/
elasticsearch_connector_views/ src/ Plugin/ views/ field/ ElasticsearchViewsEntity.php, line 177
Class
- ElasticsearchViewsEntity
- Handles the display of entity reference fields in Search API Views.
Namespace
Drupal\elasticsearch_connector_views\Plugin\views\fieldCode
public function preRender(&$values) {
parent::preRender($values);
// The parent method will just have loaded the entity IDs. We now multi-load
// the actual objects.
$property_path = $this
->getCombinedPropertyPath();
foreach ($values as $i => $row) {
if (!empty($row->{$property_path})) {
foreach ((array) $row->{$property_path} as $j => $value) {
if (is_scalar($value)) {
$to_load[$value][] = array(
$i,
$j,
);
}
}
}
}
if (empty($to_load)) {
return;
}
$entities = $this
->getEntityManager()
->getStorage($this
->getTargetEntityTypeId())
->loadMultiple(array_keys($to_load));
$account = $this
->getQuery()
->getAccessAccount();
foreach ($entities as $id => $entity) {
foreach ($to_load[$id] as list($i, $j)) {
if ($entity
->access('view', $account)) {
$values[$i]->{$property_path}[$j] = $entity;
}
}
}
}