class EntityTranslationRendererBase

Same name in other branches
  1. 9 core/modules/views/src/Entity/Render/EntityTranslationRendererBase.php \Drupal\views\Entity\Render\EntityTranslationRendererBase
  2. 10 core/modules/views/src/Entity/Render/EntityTranslationRendererBase.php \Drupal\views\Entity\Render\EntityTranslationRendererBase
  3. 11.x core/modules/views/src/Entity/Render/EntityTranslationRendererBase.php \Drupal\views\Entity\Render\EntityTranslationRendererBase

Defines a base class for entity translation renderers.

Hierarchy

Expanded class hierarchy of EntityTranslationRendererBase

File

core/modules/views/src/Entity/Render/EntityTranslationRendererBase.php, line 11

Namespace

Drupal\views\Entity\Render
View source
abstract class EntityTranslationRendererBase extends RendererBase {
    
    /**
     * Returns the language code associated with the given row.
     *
     * @param \Drupal\views\ResultRow $row
     *   The result row.
     *
     * @return string
     *   A language code.
     */
    public abstract function getLangcode(ResultRow $row);
    
    /**
     * {@inheritdoc}
     */
    public function query(QueryPluginBase $query, $relationship = NULL) {
    }
    
    /**
     * {@inheritdoc}
     */
    public function preRender(array $result) {
        $view_builder = \Drupal::entityTypeManager()->getViewBuilder($this->entityType
            ->id());
        
        /** @var \Drupal\views\ResultRow $row */
        foreach ($result as $row) {
            // @todo Take relationships into account.
            //   See https://www.drupal.org/node/2457999.
            $entity = $row->_entity;
            $entity->view = $this->view;
            $this->build[$entity->id()] = $view_builder->view($entity, $this->view->rowPlugin->options['view_mode'], $this->getLangcode($row));
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function render(ResultRow $row) {
        $entity_id = $row->_entity
            ->id();
        return $this->build[$entity_id];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
EntityTranslationRendererBase::getLangcode abstract public function Returns the language code associated with the given row. 3
EntityTranslationRendererBase::preRender public function Runs before each entity is rendered. Overrides RendererBase::preRender 1
EntityTranslationRendererBase::query public function Alters the query if needed. Overrides RendererBase::query 1
EntityTranslationRendererBase::render public function Renders entity data. Overrides RendererBase::render 1
RendererBase::$build protected property Contains an array of render arrays, one for each rendered entity.
RendererBase::$entityType protected property The type of the entity being rendered.
RendererBase::$languageManager protected property The language manager.
RendererBase::$view public property The view executable wrapping the view storage entity.
RendererBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts 2
RendererBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
RendererBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyInterface::getCacheTags
RendererBase::__construct public function Constructs a renderer object. 2

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