/**
  * {@inheritdoc}
  */
 protected function buildLocalUrl($uri, array $options = [], $collect_bubbleable_metadata = FALSE)
 {
     $generated_url = $collect_bubbleable_metadata ? new GeneratedUrl() : NULL;
     $this->addOptionDefaults($options);
     $request = $this->requestStack->getCurrentRequest();
     // Remove the base: scheme.
     // @todo Consider using a class constant for this in
     //   https://www.drupal.org/node/2417459
     $uri = substr($uri, 5);
     // Allow (outbound) path processing, if needed. A valid use case is the path
     // alias overview form:
     // @see \Drupal\path\Controller\PathController::adminOverview().
     if (!empty($options['path_processing'])) {
         // Do not pass the request, since this is a special case and we do not
         // want to include e.g. the request language in the processing.
         $uri = $this->pathProcessor->processOutbound($uri, $options, NULL, $generated_url);
     }
     // Strip leading slashes from internal paths to prevent them becoming
     // external URLs without protocol. /example.com should not be turned into
     // //example.com.
     $uri = ltrim($uri, '/');
     // Add any subdirectory where Drupal is installed.
     $current_base_path = $request->getBasePath() . '/';
     if ($options['absolute']) {
         $current_base_url = $request->getSchemeAndHttpHost() . $current_base_path;
         if (isset($options['https'])) {
             if (!empty($options['https'])) {
                 $base = str_replace('http://', 'https://', $current_base_url);
                 $options['absolute'] = TRUE;
             } else {
                 $base = str_replace('https://', 'http://', $current_base_url);
                 $options['absolute'] = TRUE;
             }
         } else {
             $base = $current_base_url;
         }
         if ($collect_bubbleable_metadata) {
             $generated_url->addCacheContexts(['url.site']);
         }
     } else {
         $base = $current_base_path;
     }
     $prefix = empty($uri) ? rtrim($options['prefix'], '/') : $options['prefix'];
     $uri = str_replace('%2F', '/', rawurlencode($prefix . $uri));
     $query = $options['query'] ? '?' . UrlHelper::buildQuery($options['query']) : '';
     $url = $base . $options['script'] . $uri . $query . $options['fragment'];
     return $collect_bubbleable_metadata ? $generated_url->setGeneratedUrl($url) : $url;
 }
示例#2
0
 /**
  * Passes the path to a processor manager to allow alterations.
  */
 protected function processPath($path, &$options = array(), BubbleableMetadata $bubbleable_metadata = NULL)
 {
     // Router-based paths may have a querystring on them.
     if ($query_pos = strpos($path, '?')) {
         // We don't need to do a strict check here because position 0 would mean we
         // have no actual path to work with.
         $actual_path = substr($path, 0, $query_pos);
         $query_string = substr($path, $query_pos);
     } else {
         $actual_path = $path;
         $query_string = '';
     }
     $path = $this->pathProcessor->processOutbound($actual_path === '/' ? $actual_path : rtrim($actual_path, '/'), $options, $this->requestStack->getCurrentRequest(), $bubbleable_metadata);
     $path .= $query_string;
     return $path;
 }