class TranslationLanguageRenderer in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php \Drupal\views\Entity\Render\TranslationLanguageRenderer
Renders entity translations in their row language.
Hierarchy
- class \Drupal\views\Entity\Render\RendererBase implements CacheableDependencyInterface
- class \Drupal\views\Entity\Render\EntityTranslationRendererBase
- class \Drupal\views\Entity\Render\TranslationLanguageRenderer
- class \Drupal\views\Entity\Render\EntityTranslationRendererBase
Expanded class hierarchy of TranslationLanguageRenderer
1 string reference to 'TranslationLanguageRenderer'
- EntityTranslationRenderTrait::getEntityTranslationRenderer in core/
modules/ views/ src/ Entity/ Render/ EntityTranslationRenderTrait.php - Returns the current renderer.
File
- core/
modules/ views/ src/ Entity/ Render/ TranslationLanguageRenderer.php, line 17 - Contains \Drupal\views\Entity\Render\TranslationLanguageRenderer.
Namespace
Drupal\views\Entity\RenderView source
class TranslationLanguageRenderer extends EntityTranslationRendererBase {
/**
* Stores the field alias of the langcode column.
*
* @var string
*/
protected $langcodeAlias;
/**
* {@inheritdoc}
*/
public function query(QueryPluginBase $query, $relationship = NULL) {
// In order to render in the translation language of the entity, we need
// to add the language code of the entity to the query. Skip if the site
// is not multilingual or the entity is not translatable.
if (!$this->languageManager
->isMultilingual() || !$this->entityType
->hasKey('langcode')) {
return;
}
$langcode_key = $this->entityType
->getKey('langcode');
$storage = \Drupal::entityManager()
->getStorage($this->entityType
->id());
if ($table = $storage
->getTableMapping()
->getFieldTableName($langcode_key)) {
$table_alias = $query
->ensureTable($table, $relationship);
$this->langcodeAlias = $query
->addField($table_alias, $langcode_key);
}
}
/**
* {@inheritdoc}
*/
public function preRender(array $result) {
$view_builder = $this->view->rowPlugin->entityManager
->getViewBuilder($this->entityType
->id());
/** @var \Drupal\views\ResultRow $row */
foreach ($result as $row) {
$entity = $row->_entity;
$entity->view = $this->view;
$langcode = $this
->getLangcode($row);
$this->build[$entity
->id()][$langcode] = $view_builder
->view($entity, $this->view->rowPlugin->options['view_mode'], $this
->getLangcode($row));
}
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $row) {
$entity_id = $row->_entity
->id();
$langcode = $this
->getLangcode($row);
return $this->build[$entity_id][$langcode];
}
/**
* {@inheritdoc}
*/
public function getLangcode(ResultRow $row) {
return isset($row->{$this->langcodeAlias}) ? $row->{$this->langcodeAlias} : $this->languageManager
->getDefaultLanguage()
->getId();
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return [
'languages:' . LanguageInterface::TYPE_CONTENT,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RendererBase:: |
protected | property | Contains an array of render arrays, one for each rendered entity. | |
RendererBase:: |
protected | property | The type of the entity being rendered. | |
RendererBase:: |
protected | property | The language manager. | |
RendererBase:: |
public | property | The view executable wrapping the view storage entity. | |
RendererBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
|
RendererBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
|
RendererBase:: |
public | function | Constructs a renderer object. | 2 |
TranslationLanguageRenderer:: |
protected | property | Stores the field alias of the langcode column. | |
TranslationLanguageRenderer:: |
public | function |
The cache contexts associated with this object. Overrides RendererBase:: |
|
TranslationLanguageRenderer:: |
public | function |
Returns the language code associated with the given row. Overrides EntityTranslationRendererBase:: |
|
TranslationLanguageRenderer:: |
public | function |
Runs before each entity is rendered. Overrides EntityTranslationRendererBase:: |
|
TranslationLanguageRenderer:: |
public | function |
Alters the query if needed. Overrides EntityTranslationRendererBase:: |
|
TranslationLanguageRenderer:: |
public | function |
Renders entity data. Overrides EntityTranslationRendererBase:: |