search_api-8.x-1.15/src/Plugin/views/EntityTranslationRenderer.php
src/Plugin/views/EntityTranslationRenderer.php
<?php
namespace Drupal\search_api\Plugin\views;
use Drupal\Core\Language\LanguageInterface;
use Drupal\views\Entity\Render\TranslationLanguageRenderer;
use Drupal\views\ResultRow as ViewsResultRow;
/**
* Renders entity translations in their row language.
*/
class EntityTranslationRenderer extends TranslationLanguageRenderer {
/**
* {@inheritdoc}
*/
public function getLangcode(ViewsResultRow $row) {
if (!empty($row->search_api_language)) {
return $row->search_api_language;
}
// If our normal query plugin is used, this shouldn't really ever happen,
// but if it does we fall back to the current request's content language.
return $this->languageManager
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();
}
}
