You are here

class WorkspacesAliasRepository in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/workspaces/src/WorkspacesAliasRepository.php \Drupal\workspaces\WorkspacesAliasRepository

Provides workspace-specific path alias lookup queries.

Hierarchy

Expanded class hierarchy of WorkspacesAliasRepository

File

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

Namespace

Drupal\workspaces
View source
class WorkspacesAliasRepository extends AliasRepository {

  /**
   * The workspace manager.
   *
   * @var \Drupal\workspaces\WorkspaceManagerInterface
   */
  protected $workspaceManager;

  /**
   * Sets the workspace manager.
   *
   * @param \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager
   *   The workspace manager service.
   *
   * @return $this
   */
  public function setWorkspacesManager(WorkspaceManagerInterface $workspace_manager) {
    $this->workspaceManager = $workspace_manager;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  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', 'base_table_2');
    $wa_join = $query
      ->leftJoin('workspace_association', NULL, "%alias.target_entity_type_id = 'path_alias' AND %alias.target_entity_id = base_table_2.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, base_table_2.revision_id)");
    return $query;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AliasRepository::$connection protected property The database connection.
AliasRepository::addLanguageFallback protected function Adds path alias language fallback conditions to a select query object.
AliasRepository::lookupByAlias public function Searches a path alias for a given alias. Overrides AliasRepositoryInterface::lookupByAlias
AliasRepository::lookupBySystemPath public function Searches a path alias for a given Drupal system path. Overrides AliasRepositoryInterface::lookupBySystemPath
AliasRepository::pathHasMatchingAlias public function Check if any alias exists starting with $initial_substring. Overrides AliasRepositoryInterface::pathHasMatchingAlias
AliasRepository::preloadPathAlias public function Pre-loads path alias information for a given list of system paths. Overrides AliasRepositoryInterface::preloadPathAlias
AliasRepository::__construct public function Constructs an AliasRepository object.
WorkspacesAliasRepository::$workspaceManager protected property The workspace manager.
WorkspacesAliasRepository::getBaseQuery protected function Returns a SELECT query for the path_alias base table. Overrides AliasRepository::getBaseQuery
WorkspacesAliasRepository::setWorkspacesManager public function Sets the workspace manager.