Skip to content
Snippets Groups Projects
Select Git revision
  • 4dfab43fd5c229aa33d0a3c9aa04d9095e2411d4
  • 11.x default protected
  • 11.2.x protected
  • 10.6.x protected
  • 10.5.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

PathProcessorAlias.php

Blame
  • Lee Rowlands's avatar
    SA-CORE-2018-006 by alexpott, attilatilman, bkosborne, catch, bonus, Wim...
    Lee Rowlands authored
    SA-CORE-2018-006 by alexpott, attilatilman, bkosborne, catch, bonus, Wim Leers, Sam152, Berdir, Damien Tournoud, Dave Reid, Kova101, David_Rothstein, dawehner, dsnopek, samuel.mortenson, stefan.r, tedbow, xjm, timmillwood, pwolanin, njbooher, dyates, effulgentsia, klausi, mlhess, larowlan
    4dfab43f
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    PathProcessorAlias.php 1.83 KiB
    <?php
    
    namespace Drupal\Core\PathProcessor;
    
    use Drupal\Core\Path\AliasManagerInterface;
    use Drupal\Core\Render\BubbleableMetadata;
    use Symfony\Component\HttpFoundation\Request;
    
    /**
     * Processes the inbound path using path alias lookups.
     */
    class PathProcessorAlias implements InboundPathProcessorInterface, OutboundPathProcessorInterface {
    
      /**
       * 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;
      }
    
      /**
       * {@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 (strpos($path, '//') === 0) {
            $path = '/' . ltrim($path, '/');
          }
        }
        return $path;
      }
    
    }