Version 1
[yaffs-website] / web / core / modules / rest / src / Plugin / views / row / DataEntityRow.php
1 <?php
2
3 namespace Drupal\rest\Plugin\views\row;
4
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\Language\LanguageManagerInterface;
7 use Drupal\views\Entity\Render\EntityTranslationRenderTrait;
8 use Drupal\views\Plugin\views\row\RowPluginBase;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12  * Plugin which displays entities as raw data.
13  *
14  * @ingroup views_row_plugins
15  *
16  * @ViewsRow(
17  *   id = "data_entity",
18  *   title = @Translation("Entity"),
19  *   help = @Translation("Use entities as row data."),
20  *   display_types = {"data"}
21  * )
22  */
23 class DataEntityRow extends RowPluginBase {
24
25   use EntityTranslationRenderTrait;
26
27   /**
28    * {@inheritdoc}
29    */
30   protected $usesOptions = FALSE;
31
32   /**
33    * Contains the entity type of this row plugin instance.
34    *
35    * @var \Drupal\Core\Entity\EntityTypeInterface
36    */
37   protected $entityType;
38
39   /**
40    * The entity manager.
41    *
42    * @var \Drupal\Core\Entity\EntityManagerInterface
43    */
44   public $entityManager;
45
46   /**
47    * The language manager.
48    *
49    * @var \Drupal\Core\Language\LanguageManagerInterface
50    */
51   protected $languageManager;
52
53   /**
54    * {@inheritdoc}
55    *
56    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
57    *   The entity manager.
58    * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
59    *   The language manager.
60    */
61   public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) {
62     parent::__construct($configuration, $plugin_id, $plugin_definition);
63
64     $this->entityManager = $entity_manager;
65     $this->languageManager = $language_manager;
66   }
67
68   /**
69    * {@inheritdoc}
70    */
71   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
72     return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity.manager'), $container->get('language_manager'));
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   public function render($row) {
79     return $this->getEntityTranslation($row->_entity, $row);
80   }
81
82   /**
83    * {@inheritdoc}
84    */
85   public function getEntityTypeId() {
86     return $this->view->getBaseEntityType()->id();
87   }
88
89   /**
90    * {@inheritdoc}
91    */
92   protected function getEntityManager() {
93     return $this->entityManager;
94   }
95
96   /**
97    * {@inheritdoc}
98    */
99   protected function getLanguageManager() {
100     return $this->languageManager;
101   }
102
103   /**
104    * {@inheritdoc}
105    */
106   protected function getView() {
107     return $this->view;
108   }
109
110   /**
111    * {@inheritdoc}
112    */
113   public function query() {
114     parent::query();
115     $this->getEntityTranslationRenderer()->query($this->view->getQuery());
116   }
117
118 }