entityManager = $entity_manager; $this->languageManager = $language_manager; } /** * {@inheritdoc} */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); $this->entityTypeId = $this->definition['entity_type']; $this->entityType = $this->entityManager->getDefinition($this->entityTypeId); $this->base_table = $this->entityType->getDataTable() ?: $this->entityType->getBaseTable(); $this->base_field = $this->entityType->getKey('id'); } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity.manager'), $container->get('language_manager')); } /** * {@inheritdoc} */ public function getEntityTypeId() { return $this->entityType->id(); } /** * {@inheritdoc} */ protected function getEntityManager() { return $this->entityManager; } /** * {@inheritdoc} */ protected function getLanguageManager() { return $this->languageManager; } /** * {@inheritdoc} */ protected function getView() { return $this->view; } /** * {@inheritdoc} */ protected function defineOptions() { $options = parent::defineOptions(); $options['view_mode'] = ['default' => 'default']; return $options; } /** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); $form['view_mode'] = [ '#type' => 'select', '#options' => \Drupal::entityManager()->getViewModeOptions($this->entityTypeId), '#title' => $this->t('View mode'), '#default_value' => $this->options['view_mode'], ]; } /** * {@inheritdoc} */ public function summaryTitle() { $options = \Drupal::entityManager()->getViewModeOptions($this->entityTypeId); if (isset($options[$this->options['view_mode']])) { return $options[$this->options['view_mode']]; } else { return $this->t('No view mode selected'); } } /** * {@inheritdoc} */ public function query() { parent::query(); $this->getEntityTranslationRenderer()->query($this->view->getQuery()); } /** * {@inheritdoc} */ public function preRender($result) { parent::preRender($result); if ($result) { $this->getEntityTranslationRenderer()->preRender($result); } } /** * {@inheritdoc} */ public function render($row) { return $this->getEntityTranslationRenderer()->render($row); } /** * {@inheritdoc} */ public function calculateDependencies() { $dependencies = parent::calculateDependencies(); $view_mode = $this->entityManager ->getStorage('entity_view_mode') ->load($this->entityTypeId . '.' . $this->options['view_mode']); if ($view_mode) { $dependencies[$view_mode->getConfigDependencyKey()][] = $view_mode->getConfigDependencyName(); } return $dependencies; } }