You are here

public function PathProcessorFront::processInbound in Drupal 10

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

File

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

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;
}