/** * {@inheritdoc} */ public function preRender($result) { // Preload each entity used in this view from the cache. This provides all // the entity values relatively cheaply, and we don't need to do it // repeatedly for the same entity if there are multiple results for one // entity. $ids = []; /** @var $row \Drupal\views\ResultRow */ foreach ($result as $row) { // Use the entity id as the key so we don't create more than one value per // entity. $entity = $row->_entity; // Node revisions need special loading. if (isset($this->view->getBaseTables()['node_revision'])) { $this->entities[$entity->id()] = \Drupal::entityManager()->getStorage('node')->loadRevision($entity->id()); } else { $ids[$entity->id()] = $entity->id(); } } $base_tables = $this->view->getBaseTables(); $base_table = key($base_tables); $table_data = Views::viewsData()->get($base_table); $this->entityType = $table_data['table']['entity type']; if (!empty($ids)) { $this->entities = \Drupal::entityManager()->getStorage($this->entityType)->loadMultiple($ids); } // Identify the date argument and fields that apply to this view. Preload // the Date Views field info for each field, keyed by the field name, so we // know how to retrieve field values from the cached node. // @todo don't hardcode $date_fields, use viewsData() or viewsDataHelper() // $data = date_views_fields($this->view->base_table); // $data = $data['name']; $data = CalendarHelper::dateViewFields($this->entityType); // $data['name'] = 'node_field_data.created_year'; $date_fields = []; /** @var $handler \Drupal\views\Plugin\views\argument\Formula */ foreach ($this->view->getDisplay()->getHandlers('argument') as $handler) { if ($handler instanceof Date) { // Strip "_calendar" from the field name. $fieldName = $handler->realField; if (!empty($data['alias'][$handler->table . '_' . $fieldName])) { $date_fields[$fieldName] = $data['alias'][$handler->table . '_' . $fieldName]; $this->dateFields = $date_fields; } $this->dateArgument = $handler; } } // // // Get the language for this view. // $this->language = $this->display->handler->get_option('field_language'); // $substitutions = views_views_query_substitutions($this->view); // if (array_key_exists($this->language, $substitutions)) { // $this->language = $substitutions[$this->language]; // } }