Chris@0: entityTranslationRenderer)) { Chris@0: $view = $this->getView(); Chris@0: $rendering_language = $view->display_handler->getOption('rendering_language'); Chris@0: $langcode = NULL; Chris@0: $dynamic_renderers = [ Chris@0: '***LANGUAGE_entity_translation***' => 'TranslationLanguageRenderer', Chris@0: '***LANGUAGE_entity_default***' => 'DefaultLanguageRenderer', Chris@0: ]; Chris@0: if (isset($dynamic_renderers[$rendering_language])) { Chris@0: // Dynamic language set based on result rows or instance defaults. Chris@0: $renderer = $dynamic_renderers[$rendering_language]; Chris@0: } Chris@0: else { Chris@0: if (strpos($rendering_language, '***LANGUAGE_') !== FALSE) { Chris@0: $langcode = PluginBase::queryLanguageSubstitutions()[$rendering_language]; Chris@0: } Chris@0: else { Chris@0: // Specific langcode set. Chris@0: $langcode = $rendering_language; Chris@0: } Chris@0: $renderer = 'ConfigurableLanguageRenderer'; Chris@0: } Chris@0: $class = '\Drupal\views\Entity\Render\\' . $renderer; Chris@0: $entity_type = $this->getEntityManager()->getDefinition($this->getEntityTypeId()); Chris@0: $this->entityTranslationRenderer = new $class($view, $this->getLanguageManager(), $entity_type, $langcode); Chris@0: } Chris@0: return $this->entityTranslationRenderer; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the entity translation matching the configured row language. Chris@0: * Chris@0: * @param \Drupal\Core\Entity\EntityInterface $entity Chris@0: * The entity object the field value being processed is attached to. Chris@0: * @param \Drupal\views\ResultRow $row Chris@0: * The result row the field value being processed belongs to. Chris@0: * Chris@0: * @return \Drupal\Core\Entity\FieldableEntityInterface Chris@0: * The entity translation object for the specified row. Chris@0: */ Chris@0: public function getEntityTranslation(EntityInterface $entity, ResultRow $row) { Chris@0: // We assume the same language should be used for all entity fields Chris@0: // belonging to a single row, even if they are attached to different entity Chris@0: // types. Below we apply language fallback to ensure a valid value is always Chris@0: // picked. Chris@0: $translation = $entity; Chris@0: if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) { Chris@0: $langcode = $this->getEntityTranslationRenderer()->getLangcode($row); Chris@0: $translation = $this->getEntityManager()->getTranslationFromContext($entity, $langcode); Chris@0: } Chris@0: return $translation; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the entity type identifier. Chris@0: * Chris@0: * @return string Chris@0: * The entity type identifier. Chris@0: */ Chris@0: abstract public function getEntityTypeId(); Chris@0: Chris@0: /** Chris@0: * Returns the entity manager. Chris@0: * Chris@0: * @return \Drupal\Core\Entity\EntityManagerInterface Chris@0: * The entity manager. Chris@0: */ Chris@0: abstract protected function getEntityManager(); Chris@0: Chris@0: /** Chris@0: * Returns the language manager. Chris@0: * Chris@0: * @return \Drupal\Core\Language\LanguageManagerInterface Chris@0: * The language manager. Chris@0: */ Chris@0: abstract protected function getLanguageManager(); Chris@0: Chris@0: /** Chris@0: * Returns the top object of a view. Chris@0: * Chris@0: * @return \Drupal\views\ViewExecutable Chris@0: * The view object. Chris@0: */ Chris@0: abstract protected function getView(); Chris@0: Chris@0: }