class TranslationLanguageRenderer in Display Suite 8.3
Same name and namespace in other branches
- 8.4 src/Plugin/views/Entity/Render/TranslationLanguageRenderer.php \Drupal\ds\Plugin\views\Entity\Render\TranslationLanguageRenderer
- 8.2 src/Plugin/views/Entity/Render/TranslationLanguageRenderer.php \Drupal\ds\Plugin\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\ds\Plugin\views\Entity\Render\RendererBase
- class \Drupal\ds\Plugin\views\Entity\Render\DefaultLanguageRenderer
- class \Drupal\ds\Plugin\views\Entity\Render\TranslationLanguageRenderer
- class \Drupal\ds\Plugin\views\Entity\Render\DefaultLanguageRenderer
- class \Drupal\ds\Plugin\views\Entity\Render\RendererBase
- class \Drupal\views\Entity\Render\EntityTranslationRendererBase
Expanded class hierarchy of TranslationLanguageRenderer
1 string reference to 'TranslationLanguageRenderer'
- EntityRow::getEntityTranslationRenderer in src/
Plugin/ views/ row/ EntityRow.php - Returns the current renderer.
File
- src/
Plugin/ views/ Entity/ Render/ TranslationLanguageRenderer.php, line 11
Namespace
Drupal\ds\Plugin\views\Entity\RenderView source
class TranslationLanguageRenderer extends DefaultLanguageRenderer {
/**
* Stores the field alias of the langcode column.
*
* @var string
*/
protected $langcodeAlias;
/**
* {@inheritdoc}
*/
public function query(QueryPluginBase $query, $relationship = NULL) {
// There is no point in getting the language, in case the site is not
// multilingual.
if (!$this->languageManager
->isMultilingual()) {
return;
}
// If the data table is defined, we use the translation language as render
// language, otherwise we fall back to the default entity language, which is
// stored in the revision table for revisionable entity types.
$langcode_key = $this->entityType
->getKey('langcode');
foreach ([
'data_table',
'revision_table',
'base_table',
] as $key) {
if ($table = $this->entityType
->get($key)) {
$table_alias = $query
->ensureTable($table);
$this->langcodeAlias = $query
->addField($table_alias, $langcode_key);
break;
}
}
}
/**
* {@inheritdoc}
*/
public function preRender(array $result) {
parent::dsPreRender($result, TRUE);
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $row) {
$entity_id = $row->_entity
->id();
$langcode = $this
->getLangcode($row);
if (isset($this->build[$entity_id][$langcode])) {
$build = $this->build[$entity_id][$langcode];
$this
->alterBuild($build, $row);
return $build;
}
return [];
}
/**
* {@inheritdoc}
*/
public function getLangcode(ResultRow $row) {
return isset($row->{$this->langcodeAlias}) ? $row->{$this->langcodeAlias} : $this->languageManager
->getDefaultLanguage()
->getId();
}
}
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:: |
protected | function | Alter the build. | |
RendererBase:: |
protected | function | Pre renders all the Display Suite rows. | |
RendererBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
2 |
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 |
Returns the language code associated to the given row. Overrides DefaultLanguageRenderer:: |
|
TranslationLanguageRenderer:: |
public | function |
Runs before each entity is rendered. Overrides RendererBase:: |
|
TranslationLanguageRenderer:: |
public | function |
Alters the query if needed. Overrides EntityTranslationRendererBase:: |
|
TranslationLanguageRenderer:: |
public | function |
Renders entity data. Overrides RendererBase:: |