TranslationLanguageRenderer.php in Display Suite 8.2
File
src/Plugin/views/Entity/Render/TranslationLanguageRenderer.php
View source
<?php
namespace Drupal\ds\Plugin\views\Entity\Render;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ResultRow;
class TranslationLanguageRenderer extends DefaultLanguageRenderer {
protected $langcodeAlias;
public function query(QueryPluginBase $query, $relationship = NULL) {
if (!$this->languageManager
->isMultilingual()) {
return;
}
$langcode_key = $this->entityType
->getKey('langcode');
foreach (array(
'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;
}
}
}
public function preRender(array $result) {
parent::dsPreRender($result, TRUE);
}
public function render(ResultRow $row) {
$entity_id = $row->_entity
->id();
$langcode = $this
->getLangcode($row);
return $this->build[$entity_id][$langcode];
}
public function getLangcode(ResultRow $row) {
return isset($row->{$this->langcodeAlias}) ? $row->{$this->langcodeAlias} : $this->languageManager
->getDefaultLanguage()
->getId();
}
}