class DomainPathAliasManager in Domain Path 8
Hierarchy
- class \Drupal\Core\Path\AliasManager implements CacheDecoratorInterface, AliasManagerInterface uses DeprecatedServicePropertyTrait
- class \Drupal\path_alias\AliasManager implements AliasManagerInterface
- class \Drupal\domain_path\DomainPathAliasManager
- class \Drupal\path_alias\AliasManager implements AliasManagerInterface
Expanded class hierarchy of DomainPathAliasManager
File
- src/
DomainPathAliasManager.php, line 12
Namespace
Drupal\domain_pathView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AliasManager:: |
protected | property | Cache backend service. | |
AliasManager:: |
protected | property | The cache key to use when caching paths. | |
AliasManager:: |
protected | property | Whether the cache needs to be written. | |
AliasManager:: |
protected | property | ||
AliasManager:: |
protected | property | Whether preloaded path lookups has already been loaded. | |
AliasManager:: |
protected | property | Language manager for retrieving the default langcode when none is specified. | |
AliasManager:: |
protected | property | Holds the map of path lookups per language. | |
AliasManager:: |
protected | property | Holds an array of paths that have no alias. | |
AliasManager:: |
protected | property | Holds an array of aliases for which no path was found. | |
AliasManager:: |
protected | property | The path alias repository. | |
AliasManager:: |
protected | property | Holds an array of previously looked up paths for the current request path. | |
AliasManager:: |
protected | property | Holds the array of whitelisted path aliases. | |
AliasManager:: |
public | function |
Clear internal caches in alias manager. Overrides AliasManagerInterface:: |
|
AliasManager:: |
protected | function | Wrapper method for REQUEST_TIME constant. | |
AliasManager:: |
protected | function | Rebuild the path alias white list. | |
AliasManager:: |
public | function |
Specify the key to use when writing the cache. Overrides CacheDecoratorInterface:: |
|
AliasManager:: |
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:: |
|
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
DomainPathAliasManager:: |
protected | property | ||
DomainPathAliasManager:: |
protected | property | ||
DomainPathAliasManager:: |
public | function |
Given a path, return the alias. Overrides AliasManager:: |
|
DomainPathAliasManager:: |
public | function |
Given the alias, return the path it represents. Overrides AliasManager:: |
|
DomainPathAliasManager:: |
public | function |
Constructs an AliasManager with DomainPathAliasManager. Overrides AliasManager:: |