3 namespace Drupal\views\Entity\Render;
5 use Drupal\Core\Cache\Cache;
6 use Drupal\Core\Cache\CacheableDependencyInterface;
7 use Drupal\Core\Entity\EntityTypeInterface;
8 use Drupal\Core\Language\LanguageManagerInterface;
9 use Drupal\views\Plugin\views\query\QueryPluginBase;
10 use Drupal\views\ResultRow;
11 use Drupal\views\ViewExecutable;
14 * Defines a base class for entity renderers.
16 abstract class RendererBase implements CacheableDependencyInterface {
19 * The view executable wrapping the view storage entity.
21 * @var \Drupal\views\ViewExecutable
26 * The language manager.
28 * @var \Drupal\Core\Language\LanguageManagerInterface
30 protected $languageManager;
33 * The type of the entity being rendered.
35 * @var \Drupal\Core\Entity\EntityTypeInterface
37 protected $entityType;
40 * Contains an array of render arrays, one for each rendered entity.
47 * Constructs a renderer object.
49 * @param \Drupal\views\ViewExecutable $view
50 * The entity row being rendered.
51 * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
52 * The language manager.
53 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
56 public function __construct(ViewExecutable $view, LanguageManagerInterface $language_manager, EntityTypeInterface $entity_type) {
58 $this->languageManager = $language_manager;
59 $this->entityType = $entity_type;
65 public function getCacheMaxAge() {
66 return Cache::PERMANENT;
72 public function getCacheContexts() {
79 public function getCacheTags() {
84 * Alters the query if needed.
86 * @param \Drupal\views\Plugin\views\query\QueryPluginBase $query
88 * @param string $relationship
89 * (optional) The relationship, used by a field.
91 abstract public function query(QueryPluginBase $query, $relationship = NULL);
94 * Runs before each entity is rendered.
97 * The full array of results from the query.
99 public function preRender(array $result) {
103 * Renders entity data.
105 * @param \Drupal\views\ResultRow $row
106 * A single row of the query result.
109 * A renderable array for the entity data contained in the result row.
111 abstract public function render(ResultRow $row);