Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\views\Entity\Render;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Cache\Cache;
|
Chris@0
|
6 use Drupal\Core\Cache\CacheableDependencyInterface;
|
Chris@0
|
7 use Drupal\Core\Entity\EntityTypeInterface;
|
Chris@0
|
8 use Drupal\Core\Language\LanguageManagerInterface;
|
Chris@0
|
9 use Drupal\views\Plugin\views\query\QueryPluginBase;
|
Chris@0
|
10 use Drupal\views\ResultRow;
|
Chris@0
|
11 use Drupal\views\ViewExecutable;
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * Defines a base class for entity renderers.
|
Chris@0
|
15 */
|
Chris@0
|
16 abstract class RendererBase implements CacheableDependencyInterface {
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * The view executable wrapping the view storage entity.
|
Chris@0
|
20 *
|
Chris@0
|
21 * @var \Drupal\views\ViewExecutable
|
Chris@0
|
22 */
|
Chris@0
|
23 public $view;
|
Chris@0
|
24
|
Chris@0
|
25 /**
|
Chris@0
|
26 * The language manager.
|
Chris@0
|
27 *
|
Chris@0
|
28 * @var \Drupal\Core\Language\LanguageManagerInterface
|
Chris@0
|
29 */
|
Chris@0
|
30 protected $languageManager;
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * The type of the entity being rendered.
|
Chris@0
|
34 *
|
Chris@0
|
35 * @var \Drupal\Core\Entity\EntityTypeInterface
|
Chris@0
|
36 */
|
Chris@0
|
37 protected $entityType;
|
Chris@0
|
38
|
Chris@0
|
39 /**
|
Chris@0
|
40 * Contains an array of render arrays, one for each rendered entity.
|
Chris@0
|
41 *
|
Chris@0
|
42 * @var array
|
Chris@0
|
43 */
|
Chris@0
|
44 protected $build;
|
Chris@0
|
45
|
Chris@0
|
46 /**
|
Chris@0
|
47 * Constructs a renderer object.
|
Chris@0
|
48 *
|
Chris@0
|
49 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
50 * The entity row being rendered.
|
Chris@0
|
51 * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
Chris@0
|
52 * The language manager.
|
Chris@0
|
53 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
Chris@0
|
54 * The entity type.
|
Chris@0
|
55 */
|
Chris@0
|
56 public function __construct(ViewExecutable $view, LanguageManagerInterface $language_manager, EntityTypeInterface $entity_type) {
|
Chris@0
|
57 $this->view = $view;
|
Chris@0
|
58 $this->languageManager = $language_manager;
|
Chris@0
|
59 $this->entityType = $entity_type;
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 /**
|
Chris@0
|
63 * {@inheritdoc}
|
Chris@0
|
64 */
|
Chris@0
|
65 public function getCacheMaxAge() {
|
Chris@0
|
66 return Cache::PERMANENT;
|
Chris@0
|
67 }
|
Chris@0
|
68
|
Chris@0
|
69 /**
|
Chris@0
|
70 * {@inheritdoc}
|
Chris@0
|
71 */
|
Chris@0
|
72 public function getCacheContexts() {
|
Chris@0
|
73 return [];
|
Chris@0
|
74 }
|
Chris@0
|
75
|
Chris@0
|
76 /**
|
Chris@0
|
77 * {@inheritdoc}
|
Chris@0
|
78 */
|
Chris@0
|
79 public function getCacheTags() {
|
Chris@0
|
80 return [];
|
Chris@0
|
81 }
|
Chris@0
|
82
|
Chris@0
|
83 /**
|
Chris@0
|
84 * Alters the query if needed.
|
Chris@0
|
85 *
|
Chris@0
|
86 * @param \Drupal\views\Plugin\views\query\QueryPluginBase $query
|
Chris@0
|
87 * The query to alter.
|
Chris@0
|
88 * @param string $relationship
|
Chris@0
|
89 * (optional) The relationship, used by a field.
|
Chris@0
|
90 */
|
Chris@0
|
91 abstract public function query(QueryPluginBase $query, $relationship = NULL);
|
Chris@0
|
92
|
Chris@0
|
93 /**
|
Chris@0
|
94 * Runs before each entity is rendered.
|
Chris@0
|
95 *
|
Chris@0
|
96 * @param $result
|
Chris@0
|
97 * The full array of results from the query.
|
Chris@0
|
98 */
|
Chris@0
|
99 public function preRender(array $result) {
|
Chris@0
|
100 }
|
Chris@0
|
101
|
Chris@0
|
102 /**
|
Chris@0
|
103 * Renders entity data.
|
Chris@0
|
104 *
|
Chris@0
|
105 * @param \Drupal\views\ResultRow $row
|
Chris@0
|
106 * A single row of the query result.
|
Chris@0
|
107 *
|
Chris@0
|
108 * @return array
|
Chris@0
|
109 * A renderable array for the entity data contained in the result row.
|
Chris@0
|
110 */
|
Chris@0
|
111 abstract public function render(ResultRow $row);
|
Chris@0
|
112
|
Chris@0
|
113 }
|