You are here

protected function TranslationCountTrait::joinLanguages in Translation Views 8

Ensure that translations table is joined.

Parameters

\Drupal\views\Plugin\views\query\Sql $query: Views sql query.

Return value

string The table alias after joining a table.

2 calls to TranslationCountTrait::joinLanguages()
TranslationCountField::query in src/Plugin/views/field/TranslationCountField.php
Called to add the field to a query.
TranslationCountFilter::query in src/Plugin/views/filter/TranslationCountFilter.php
Add this filter to the query.

File

src/TranslationCountTrait.php, line 24

Class

TranslationCountTrait
Defines translation count trait.

Namespace

Drupal\translation_views

Code

protected function joinLanguages(ViewsSqlQuery &$query) {
  if (empty($query->tables[$this->tableAlias])) {
    $query_base_table = $this->relationship ?: $this->view->storage
      ->get('base_table');
    $entity_type = $this->entityTypeManager
      ->getDefinition($this
      ->getEntityType());
    $keys = $entity_type
      ->getKeys();
    $definition = [
      'type' => 'LEFT',
      'left_field' => $keys['id'],
      'field' => $keys['id'],
      'table' => $query_base_table,
      'left_table' => $query_base_table,
      'include_original_language' => !empty($this->options['include_original_language']),
      'langcodes_as_count' => TRUE,
      'entity_id' => $keys['id'],
    ];
    $tableAlias = $query
      ->ensureTable($query_base_table, $this->relationship);
    $join = $this->joinHandler
      ->createInstance('translation_views_language_join', $definition);
    return $query
      ->addTable($query_base_table, $tableAlias, $join, $this->tableAlias);
  }
  else {
    return $this->tableAlias;
  }
}