b85737f3cf13da873875959633c315fa93904bee
[yaffs-website] / web / core / lib / Drupal / Core / PathProcessor / PathProcessorAlias.php
1 <?php
2
3 namespace Drupal\Core\PathProcessor;
4
5 use Drupal\Core\Path\AliasManagerInterface;
6 use Drupal\Core\Render\BubbleableMetadata;
7 use Symfony\Component\HttpFoundation\Request;
8
9 /**
10  * Processes the inbound path using path alias lookups.
11  */
12 class PathProcessorAlias implements InboundPathProcessorInterface, OutboundPathProcessorInterface {
13
14   /**
15    * An alias manager for looking up the system path.
16    *
17    * @var \Drupal\Core\Path\AliasManagerInterface
18    */
19   protected $aliasManager;
20
21   /**
22    * Constructs a PathProcessorAlias object.
23    *
24    * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
25    *   An alias manager for looking up the system path.
26    */
27   public function __construct(AliasManagerInterface $alias_manager) {
28     $this->aliasManager = $alias_manager;
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function processInbound($path, Request $request) {
35     $path = $this->aliasManager->getPathByAlias($path);
36     return $path;
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
43     if (empty($options['alias'])) {
44       $langcode = isset($options['language']) ? $options['language']->getId() : NULL;
45       $path = $this->aliasManager->getAliasByPath($path, $langcode);
46     }
47     return $path;
48   }
49
50 }