Mercurial > hg > isophonics-drupal-site
annotate core/modules/views/src/Entity/Render/EntityTranslationRendererBase.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | af1871eacc83 |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\views\Entity\Render; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\views\Plugin\views\query\QueryPluginBase; |
Chris@0 | 6 use Drupal\views\ResultRow; |
Chris@0 | 7 |
Chris@0 | 8 /** |
Chris@0 | 9 * Defines a base class for entity translation renderers. |
Chris@0 | 10 */ |
Chris@0 | 11 abstract class EntityTranslationRendererBase extends RendererBase { |
Chris@0 | 12 |
Chris@0 | 13 /** |
Chris@0 | 14 * Returns the language code associated with the given row. |
Chris@0 | 15 * |
Chris@0 | 16 * @param \Drupal\views\ResultRow $row |
Chris@0 | 17 * The result row. |
Chris@0 | 18 * |
Chris@0 | 19 * @return string |
Chris@0 | 20 * A language code. |
Chris@0 | 21 */ |
Chris@0 | 22 abstract public function getLangcode(ResultRow $row); |
Chris@0 | 23 |
Chris@0 | 24 /** |
Chris@0 | 25 * {@inheritdoc} |
Chris@0 | 26 */ |
Chris@0 | 27 public function query(QueryPluginBase $query, $relationship = NULL) { |
Chris@0 | 28 } |
Chris@0 | 29 |
Chris@0 | 30 /** |
Chris@0 | 31 * {@inheritdoc} |
Chris@0 | 32 */ |
Chris@0 | 33 public function preRender(array $result) { |
Chris@18 | 34 $view_builder = \Drupal::entityTypeManager()->getViewBuilder($this->entityType->id()); |
Chris@0 | 35 |
Chris@0 | 36 /** @var \Drupal\views\ResultRow $row */ |
Chris@0 | 37 foreach ($result as $row) { |
Chris@0 | 38 // @todo Take relationships into account. |
Chris@0 | 39 // See https://www.drupal.org/node/2457999. |
Chris@0 | 40 $entity = $row->_entity; |
Chris@0 | 41 $entity->view = $this->view; |
Chris@0 | 42 $this->build[$entity->id()] = $view_builder->view($entity, $this->view->rowPlugin->options['view_mode'], $this->getLangcode($row)); |
Chris@0 | 43 } |
Chris@0 | 44 } |
Chris@0 | 45 |
Chris@0 | 46 /** |
Chris@0 | 47 * {@inheritdoc} |
Chris@0 | 48 */ |
Chris@0 | 49 public function render(ResultRow $row) { |
Chris@0 | 50 $entity_id = $row->_entity->id(); |
Chris@0 | 51 return $this->build[$entity_id]; |
Chris@0 | 52 } |
Chris@0 | 53 |
Chris@0 | 54 } |