PathProcessorAlias.php 1.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php

/**
 * @file
 * Contains \Drupal\Core\PathProcessor\PathProcessorAlias.
 */

namespace Drupal\Core\PathProcessor;

use Drupal\Core\Path\AliasManagerInterface;
use Symfony\Component\HttpFoundation\Request;

/**
 * Processes the inbound path using path alias lookups.
 */
16
class PathProcessorAlias implements InboundPathProcessorInterface, OutboundPathProcessorInterface {
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

  /**
   * An alias manager for looking up the system path.
   *
   * @var \Drupal\Core\Path\AliasManagerInterface
   */
  protected $aliasManager;

  /**
   * Constructs a PathProcessorAlias object.
   *
   * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
   *   An alias manager for looking up the system path.
   */
  public function __construct(AliasManagerInterface $alias_manager) {
    $this->aliasManager = $alias_manager;
  }

  /**
   * Implements Drupal\Core\PathProcessor\InboundPathProcessorInterface::processInbound().
   */
  public function processInbound($path, Request $request) {
39
    $path = $this->aliasManager->getPathByAlias($path);
40 41 42
    return $path;
  }

43 44 45 46
  /**
   * Implements Drupal\Core\PathProcessor\OutboundPathProcessorInterface::processOutbound().
   */
  public function processOutbound($path, &$options = array(), Request $request = NULL) {
47 48
    if (empty($options['alias'])) {
      $langcode = isset($options['language']) ? $options['language']->id : NULL;
49
      $path = $this->aliasManager->getAliasByPath($path, $langcode);
50
    }
51 52
    return $path;
  }
53

54
}