Mercurial > hg > isophonics-drupal-site
comparison core/modules/views/src/Entity/Render/EntityTranslationRendererBase.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 } |