public function DomainPathAliasManager::getAliasByPath in Domain Path 8
Given a path, return the alias.
Parameters
string $path: A path.
string $langcode: An optional language code to look up the path in.
Return value
string An alias that represents the path, or path if no alias was found.
Throws
\InvalidArgumentException Thrown when the path does not start with a slash.
Overrides AliasManager::getAliasByPath
File
- src/
DomainPathAliasManager.php, line 64
Class
Namespace
Drupal\domain_pathCode
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);
}