"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/lib/Drupal/Core/RouteProcessor/RouteProcessorCurrent.php" (26 Nov 2020, 1936 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "RouteProcessorCurrent.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\Core\RouteProcessor;
    4 
    5 use Drupal\Core\Render\BubbleableMetadata;
    6 use Drupal\Core\Routing\RouteMatchInterface;
    7 use Symfony\Component\Routing\Route;
    8 
    9 /**
   10  * Provides a route processor to replace <current>.
   11  */
   12 class RouteProcessorCurrent implements OutboundRouteProcessorInterface {
   13 
   14   /**
   15    * The current route match.
   16    *
   17    * @var \Drupal\Core\Routing\RouteMatchInterface
   18    */
   19   protected $routeMatch;
   20 
   21   /**
   22    * Constructs a new RouteProcessorCurrent.
   23    *
   24    * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   25    *   The current route match.
   26    */
   27   public function __construct(RouteMatchInterface $route_match) {
   28     $this->routeMatch = $route_match;
   29   }
   30 
   31   /**
   32    * {@inheritdoc}
   33    */
   34   public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) {
   35     if ($route_name === '<current>') {
   36       if ($current_route = $this->routeMatch->getRouteObject()) {
   37         $requirements = $current_route->getRequirements();
   38         // Setting _method and _schema is deprecated since 2.7. Using
   39         // setMethods() and setSchemes() are now the recommended ways.
   40         unset($requirements['_method']);
   41         unset($requirements['_schema']);
   42         $route->setRequirements($requirements);
   43 
   44         $route->setPath($current_route->getPath());
   45         $route->setSchemes($current_route->getSchemes());
   46         $route->setMethods($current_route->getMethods());
   47         $route->setOptions($current_route->getOptions());
   48         $route->setDefaults($current_route->getDefaults());
   49         $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
   50         if ($bubbleable_metadata) {
   51           $bubbleable_metadata->addCacheContexts(['route']);
   52         }
   53       }
   54       else {
   55         // If we have no current route match available, point to the frontpage.
   56         $route->setPath('/');
   57       }
   58     }
   59   }
   60 
   61 }