You are here

class PathProcessorFront in Drupal 10

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

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

Hierarchy

  • class \Drupal\Core\PathProcessor\PathProcessorFront implements \Drupal\Core\PathProcessor\InboundPathProcessorInterface

Expanded class hierarchy of PathProcessorFront

2 files declare their use of PathProcessorFront
PathProcessorFrontTest.php in core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php
PathProcessorTest.php in core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
1 string reference to 'PathProcessorFront'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses PathProcessorFront
path_processor_front in core/core.services.yml
Drupal\Core\PathProcessor\PathProcessorFront

File

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

Namespace

Drupal\Core\PathProcessor
View source
class PathProcessorFront implements InboundPathProcessorInterface {

  /**
   * A config factory for retrieving required config settings.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $config;

  /**
   * Constructs a PathProcessorFront object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config
   *   A config factory for retrieving the site front page configuration.
   */
  public function __construct(ConfigFactoryInterface $config) {
    $this->config = $config;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members