You are here

class DomainPathAliasManager in Domain Path 8

Hierarchy

Expanded class hierarchy of DomainPathAliasManager

File

src/DomainPathAliasManager.php, line 12

Namespace

Drupal\domain_path
View source
class DomainPathAliasManager extends AliasManager {
  protected $method;
  protected $domainPath;

  /**
   * Constructs an AliasManager with DomainPathAliasManager.
   *
   * @param \Drupal\path_alias\AliasRepositoryInterface $alias_repository
   *   The path alias repository.
   * @param \Drupal\path_alias\AliasWhitelistInterface $whitelist
   *   The whitelist implementation to use.
   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
   *   The language manager.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache
   *   Cache backend.
   */
  public function __construct($alias_repository, AliasWhitelistInterface $whitelist, LanguageManagerInterface $language_manager, CacheBackendInterface $cache) {
    parent::__construct($alias_repository, $whitelist, $language_manager, $cache);
  }
  public function getPathByAlias($alias, $langcode = NULL) {
    $config = \Drupal::config('domain_path.settings');
    $this->method = $config
      ->get('language_method') ? $config
      ->get('language_method') : LanguageInterface::TYPE_CONTENT;
    $active = \Drupal::service('domain.negotiator')
      ->getActiveDomain();
    if ($active === NULL) {
      $active = \Drupal::service('domain.negotiator')
        ->getActiveDomain(TRUE);
    }
    if ($active) {
      $properties = [
        'alias' => $alias,
        'domain_id' => \Drupal::service('domain.negotiator')
          ->getActiveDomain()
          ->id(),
      ];

      //https://git.drupalcode.org/project/drupal/-/blob/9.2.x/core/modules/path_alias/src/PathProcessor/AliasPathProcessor.php#L36

      //didn't pass the $langcode.
      $langcode = $langcode ?: $this->languageManager
        ->getCurrentLanguage($this->method)
        ->getId();
      if ($langcode != NULL) {
        $properties['language'] = $langcode;
      }
      else {

        //TODO: zxx -> Not applicable
        $properties['language'] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
      }
      $domain_paths = \Drupal::entityTypeManager()
        ->getStorage('domain_path')
        ->loadByProperties($properties);
      $this->domainPath = reset($domain_paths);
      if ($this->domainPath) {
        return $this->domainPath
          ->getSource();
      }
    }
    return parent::getPathByAlias($alias, $langcode);
  }
  public function getAliasByPath($path, $langcode = NULL) {
    $config = \Drupal::config('domain_path.settings');
    $this->method = $config
      ->get('language_method') ? $config
      ->get('language_method') : LanguageInterface::TYPE_CONTENT;
    $active = \Drupal::service('domain.negotiator')
      ->getActiveDomain();
    if ($active === NULL) {
      $active = \Drupal::service('domain.negotiator')
        ->getActiveDomain(TRUE);
    }
    if ($active) {
      $properties = [
        'source' => $path,
        'domain_id' => \Drupal::service('domain.negotiator')
          ->getActiveDomain()
          ->id(),
      ];
      $langcode = $langcode ?: $this->languageManager
        ->getCurrentLanguage($this->method)
        ->getId();
      if ($langcode != NULL) {
        $properties['language'] = $langcode;
      }
      $domain_paths = \Drupal::entityTypeManager()
        ->getStorage('domain_path')
        ->loadByProperties($properties);
      $this->domainPath = reset($domain_paths);
      if ($this->domainPath) {
        return $this->domainPath
          ->getAlias();
      }
    }
    return parent::getAliasByPath($path, $langcode);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AliasManager::$cache protected property Cache backend service.
AliasManager::$cacheKey protected property The cache key to use when caching paths.
AliasManager::$cacheNeedsWriting protected property Whether the cache needs to be written.
AliasManager::$deprecatedProperties protected property
AliasManager::$langcodePreloaded protected property Whether preloaded path lookups has already been loaded.
AliasManager::$languageManager protected property Language manager for retrieving the default langcode when none is specified.
AliasManager::$lookupMap protected property Holds the map of path lookups per language.
AliasManager::$noAlias protected property Holds an array of paths that have no alias.
AliasManager::$noPath protected property Holds an array of aliases for which no path was found.
AliasManager::$pathAliasRepository protected property The path alias repository.
AliasManager::$preloadedPathLookups protected property Holds an array of previously looked up paths for the current request path.
AliasManager::$whitelist protected property Holds the array of whitelisted path aliases.
AliasManager::cacheClear public function Clear internal caches in alias manager. Overrides AliasManagerInterface::cacheClear
AliasManager::getRequestTime protected function Wrapper method for REQUEST_TIME constant.
AliasManager::pathAliasWhitelistRebuild protected function Rebuild the path alias white list.
AliasManager::setCacheKey public function Specify the key to use when writing the cache. Overrides CacheDecoratorInterface::setCacheKey
AliasManager::writeCache public function Cache an array of the paths available on each page. We assume that aliases will be needed for the majority of these paths during subsequent requests, and load them in a single query during path alias lookup. Overrides CacheDecoratorInterface::writeCache
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
DomainPathAliasManager::$domainPath protected property
DomainPathAliasManager::$method protected property
DomainPathAliasManager::getAliasByPath public function Given a path, return the alias. Overrides AliasManager::getAliasByPath
DomainPathAliasManager::getPathByAlias public function Given the alias, return the path it represents. Overrides AliasManager::getPathByAlias
DomainPathAliasManager::__construct public function Constructs an AliasManager with DomainPathAliasManager. Overrides AliasManager::__construct