function WorkspacesAliasRepository::getBaseQuery

Same name in other branches
  1. 9 core/modules/workspaces/src/WorkspacesAliasRepository.php \Drupal\workspaces\WorkspacesAliasRepository::getBaseQuery()
  2. 8.9.x core/modules/workspaces/src/WorkspacesAliasRepository.php \Drupal\workspaces\WorkspacesAliasRepository::getBaseQuery()
  3. 10 core/modules/workspaces/src/WorkspacesAliasRepository.php \Drupal\workspaces\WorkspacesAliasRepository::getBaseQuery()

Overrides AliasRepository::getBaseQuery

File

core/modules/workspaces/src/WorkspacesAliasRepository.php, line 35

Class

WorkspacesAliasRepository
Provides workspace-specific path alias lookup queries.

Namespace

Drupal\workspaces

Code

protected function getBaseQuery() {
    // Don't alter any queries if we're not in a workspace context.
    if (!$this->workspaceManager
        ->hasActiveWorkspace()) {
        return parent::getBaseQuery();
    }
    $active_workspace = $this->workspaceManager
        ->getActiveWorkspace();
    $query = $this->connection
        ->select('path_alias', 'original_base_table');
    $wa_join = $query->leftJoin('workspace_association', NULL, "[%alias].[target_entity_type_id] = 'path_alias' AND [%alias].[target_entity_id] = [original_base_table].[id] AND [%alias].[workspace] = :active_workspace_id", [
        ':active_workspace_id' => $active_workspace->id(),
    ]);
    $query->innerJoin('path_alias_revision', 'base_table', "[%alias].[revision_id] = COALESCE([{$wa_join}].[target_entity_revision_id], [original_base_table].[revision_id]) AND [%alias].[langcode] = [original_base_table].[langcode]");
    $query->condition('base_table.status', 1);
    return $query;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.