function EntityTranslationRenderTrait::getEntityTranslationRenderer

Same name in other branches
  1. 9 core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.php \Drupal\views\Entity\Render\EntityTranslationRenderTrait::getEntityTranslationRenderer()
  2. 8.9.x core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.php \Drupal\views\Entity\Render\EntityTranslationRenderTrait::getEntityTranslationRenderer()
  3. 11.x core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.php \Drupal\views\Entity\Render\EntityTranslationRenderTrait::getEntityTranslationRenderer()

Returns the current renderer.

Return value

\Drupal\views\Entity\Render\EntityTranslationRendererBase The configured renderer.

File

core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.php, line 28

Class

EntityTranslationRenderTrait
Trait used to instantiate the view's entity translation renderer.

Namespace

Drupal\views\Entity\Render

Code

protected function getEntityTranslationRenderer() {
    if (!isset($this->entityTranslationRenderer)) {
        $view = $this->getView();
        $rendering_language = $view->display_handler
            ->getOption('rendering_language');
        $langcode = NULL;
        $dynamic_renderers = [
            '***LANGUAGE_entity_translation***' => 'TranslationLanguageRenderer',
            '***LANGUAGE_entity_default***' => 'DefaultLanguageRenderer',
        ];
        $entity_type = $this->getEntityTypeManager()
            ->getDefinition($this->getEntityTypeId());
        if (isset($dynamic_renderers[$rendering_language])) {
            // Dynamic language set based on result rows or instance defaults.
            $class = '\\Drupal\\views\\Entity\\Render\\' . $dynamic_renderers[$rendering_language];
            $this->entityTranslationRenderer = new $class($view, $this->getLanguageManager(), $entity_type);
        }
        else {
            if (str_contains($rendering_language, '***LANGUAGE_')) {
                $langcode = PluginBase::queryLanguageSubstitutions()[$rendering_language];
            }
            else {
                // Specific langcode set.
                $langcode = $rendering_language;
            }
            $this->entityTranslationRenderer = new ConfigurableLanguageRenderer($view, $this->getLanguageManager(), $entity_type, $langcode);
        }
    }
    return $this->entityTranslationRenderer;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.