NullGenerator.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Routing/NullGenerator.php
  2. 8.9.x core/lib/Drupal/Core/Routing/NullGenerator.php
  3. 10 core/lib/Drupal/Core/Routing/NullGenerator.php

Namespace

Drupal\Core\Routing

File

core/lib/Drupal/Core/Routing/NullGenerator.php

View source
<?php

namespace Drupal\Core\Routing;

use Drupal\Core\Render\BubbleableMetadata;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\Route;

/**
 * No-op implementation of a URL Generator, needed for backward compatibility.
 */
class NullGenerator extends UrlGenerator {
    
    /**
     * Override the parent constructor.
     *
     * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
     *   The request stack.
     */
    public function __construct(RequestStack $request_stack) {
        $this->requestStack = $request_stack;
        $this->context = new RequestContext();
    }
    
    /**
     * {@inheritdoc}
     *
     * Methods generate(), generateFromRoute() and getPathFromRoute() all call
     * this protected method.
     */
    protected function getRoute($name) {
        if ($name === '<front>') {
            return new Route('/');
        }
        elseif ($name === '<current>') {
            return new Route($this->requestStack
                ->getCurrentRequest()
                ->getPathInfo());
        }
        elseif ($name === '<none>') {
            return new Route('');
        }
        throw new RouteNotFoundException();
    }
    
    /**
     * {@inheritdoc}
     */
    protected function processRoute($name, Route $route, array &$parameters, ?BubbleableMetadata $bubbleable_metadata = NULL) {
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getInternalPathFromRoute($name, Route $route, $parameters = [], &$query_params = []) {
        return $route->getPath();
    }
    
    /**
     * {@inheritdoc}
     */
    protected function processPath($path, &$options = [], ?BubbleableMetadata $bubbleable_metadata = NULL) {
        return $path;
    }

}

Classes

Title Deprecated Summary
NullGenerator No-op implementation of a URL Generator, needed for backward compatibility.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.