You are here

public function PathProcessorFront::processInbound in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php \Drupal\Core\PathProcessor\PathProcessorFront::processInbound()

Processes the inbound path.

Implementations may make changes to the request object passed in but should avoid all other side effects. This method can be called to process requests other than the current request.

Parameters

string $path: The path to process, with a leading slash.

\Symfony\Component\HttpFoundation\Request $request: The HttpRequest object representing the request to process. Note, if this method is being called via the path_processor_manager service and is not part of routing, the current request object must be cloned before being passed in.

Return value

string The processed path.

Overrides InboundPathProcessorInterface::processInbound

File

core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php, line 37

Class

PathProcessorFront
Processes the inbound path by resolving it to the front page if empty.

Namespace

Drupal\Core\PathProcessor

Code

public function processInbound($path, Request $request) {
  if ($path === '/') {
    $path = $this->config
      ->get('system.site')
      ->get('page.front');
    if (empty($path)) {

      // We have to return a valid path but / won't be routable and config
      // might be broken so stop execution.
      throw new NotFoundHttpException();
    }
    $components = parse_url($path);

    // Remove query string and fragment.
    $path = $components['path'];

    // Merge query parameters from front page configuration value
    // with URL query, so that actual URL takes precedence.
    if (!empty($components['query'])) {
      parse_str($components['query'], $parameters);
      array_replace($parameters, $request->query
        ->all());
      $request->query
        ->replace($parameters);
    }
  }
  return $path;
}