class AliasPathProcessor
Same name in other branches
- 9 core/modules/path_alias/src/PathProcessor/AliasPathProcessor.php \Drupal\path_alias\PathProcessor\AliasPathProcessor
- 8.9.x core/modules/path_alias/src/PathProcessor/AliasPathProcessor.php \Drupal\path_alias\PathProcessor\AliasPathProcessor
- 10 core/modules/path_alias/src/PathProcessor/AliasPathProcessor.php \Drupal\path_alias\PathProcessor\AliasPathProcessor
Processes the inbound path using path alias lookups.
Hierarchy
- class \Drupal\path_alias\PathProcessor\AliasPathProcessor implements \Drupal\Core\PathProcessor\InboundPathProcessorInterface, \Drupal\Core\PathProcessor\OutboundPathProcessorInterface
Expanded class hierarchy of AliasPathProcessor
3 files declare their use of AliasPathProcessor
- AliasPathProcessorTest.php in core/
modules/ path_alias/ tests/ src/ Unit/ PathProcessor/ AliasPathProcessorTest.php - PathProcessorTest.php in core/
tests/ Drupal/ Tests/ Core/ PathProcessor/ PathProcessorTest.php - UrlGeneratorTest.php in core/
tests/ Drupal/ Tests/ Core/ Routing/ UrlGeneratorTest.php
1 string reference to 'AliasPathProcessor'
- path_alias.services.yml in core/
modules/ path_alias/ path_alias.services.yml - core/modules/path_alias/path_alias.services.yml
1 service uses AliasPathProcessor
- path_alias.path_processor in core/
modules/ path_alias/ path_alias.services.yml - Drupal\path_alias\PathProcessor\AliasPathProcessor
File
-
core/
modules/ path_alias/ src/ PathProcessor/ AliasPathProcessor.php, line 14
Namespace
Drupal\path_alias\PathProcessorView source
class AliasPathProcessor implements InboundPathProcessorInterface, OutboundPathProcessorInterface {
/**
* An alias manager for looking up the system path.
*
* @var \Drupal\path_alias\AliasManagerInterface
*/
protected $aliasManager;
/**
* Constructs a AliasPathProcessor object.
*
* @param \Drupal\path_alias\AliasManagerInterface $alias_manager
* An alias manager for looking up the system path.
*/
public function __construct(AliasManagerInterface $alias_manager) {
$this->aliasManager = $alias_manager;
}
/**
* {@inheritdoc}
*/
public function processInbound($path, Request $request) {
$path = $this->aliasManager
->getPathByAlias($path);
return $path;
}
/**
* {@inheritdoc}
*/
public function processOutbound($path, &$options = [], ?Request $request = NULL, ?BubbleableMetadata $bubbleable_metadata = NULL) {
if (empty($options['alias'])) {
$langcode = isset($options['language']) ? $options['language']->getId() : NULL;
$path = $this->aliasManager
->getAliasByPath($path, $langcode);
// Ensure the resulting path has at most one leading slash, to prevent it
// becoming an external URL without a protocol like //example.com. This
// is done in \Drupal\Core\Routing\UrlGenerator::generateFromRoute()
// also, to protect against this problem in arbitrary path processors,
// but it is duplicated here to protect any other URL generation code
// that might call this method separately.
if (str_starts_with($path, '//')) {
$path = '/' . ltrim($path, '/');
}
}
return $path;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
AliasPathProcessor::$aliasManager | protected | property | An alias manager for looking up the system path. | |
AliasPathProcessor::processInbound | public | function | Processes the inbound path. | Overrides InboundPathProcessorInterface::processInbound |
AliasPathProcessor::processOutbound | public | function | Processes the outbound path. | Overrides OutboundPathProcessorInterface::processOutbound |
AliasPathProcessor::__construct | public | function | Constructs a AliasPathProcessor object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.