Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / views / src / Entity / Render / EntityTranslationRendererBase.php
1 <?php
2
3 namespace Drupal\views\Entity\Render;
4
5 use Drupal\views\Plugin\views\query\QueryPluginBase;
6 use Drupal\views\ResultRow;
7
8 /**
9  * Defines a base class for entity translation renderers.
10  */
11 abstract class EntityTranslationRendererBase extends RendererBase {
12
13   /**
14    * Returns the language code associated with the given row.
15    *
16    * @param \Drupal\views\ResultRow $row
17    *   The result row.
18    *
19    * @return string
20    *   A language code.
21    */
22   abstract public function getLangcode(ResultRow $row);
23
24   /**
25    * {@inheritdoc}
26    */
27   public function query(QueryPluginBase $query, $relationship = NULL) {
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public function preRender(array $result) {
34     $view_builder = $this->view->rowPlugin->entityManager->getViewBuilder($this->entityType->id());
35
36     /** @var \Drupal\views\ResultRow $row */
37     foreach ($result as $row) {
38       // @todo Take relationships into account.
39       //   See https://www.drupal.org/node/2457999.
40       $entity = $row->_entity;
41       $entity->view = $this->view;
42       $this->build[$entity->id()] = $view_builder->view($entity, $this->view->rowPlugin->options['view_mode'], $this->getLangcode($row));
43     }
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function render(ResultRow $row) {
50     $entity_id = $row->_entity->id();
51     return $this->build[$entity_id];
52   }
53
54 }