From de5830d66578d6163c9ee4c3c8fd15c98fb5dfd5 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Wed, 1 Oct 2014 10:53:56 +0200
Subject: [PATCH] Issue #2346283 by damiankloip: Add route name parameter to
 OutboundRouteProcessorInterface.

---
 .../lib/Drupal/Core/Access/RouteProcessorCsrf.php |  2 +-
 .../OutboundRouteProcessorInterface.php           |  5 +++--
 .../Core/RouteProcessor/RouteProcessorManager.php |  4 ++--
 core/lib/Drupal/Core/Routing/NullGenerator.php    |  2 +-
 core/lib/Drupal/Core/Routing/UrlGenerator.php     |  9 +++++----
 .../Tests/Core/Access/RouteProcessorCsrfTest.php  |  8 ++++----
 .../RouteProcessor/RouteProcessorManagerTest.php  | 15 +++++++++------
 7 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/core/lib/Drupal/Core/Access/RouteProcessorCsrf.php b/core/lib/Drupal/Core/Access/RouteProcessorCsrf.php
index b2137d9cfead..b4851c71a35d 100644
--- a/core/lib/Drupal/Core/Access/RouteProcessorCsrf.php
+++ b/core/lib/Drupal/Core/Access/RouteProcessorCsrf.php
@@ -37,7 +37,7 @@ function __construct(CsrfTokenGenerator $csrf_token) {
   /**
    * {@inheritdoc}
    */
-  public function processOutbound(Route $route, array &$parameters) {
+  public function processOutbound($route_name, Route $route, array &$parameters) {
     if ($route->hasRequirement('_csrf_token')) {
       $path = ltrim($route->getPath(), '/');
       // Replace the path parameters with values from the parameters array.
diff --git a/core/lib/Drupal/Core/RouteProcessor/OutboundRouteProcessorInterface.php b/core/lib/Drupal/Core/RouteProcessor/OutboundRouteProcessorInterface.php
index c9bda247fe8d..145c8eea63fa 100644
--- a/core/lib/Drupal/Core/RouteProcessor/OutboundRouteProcessorInterface.php
+++ b/core/lib/Drupal/Core/RouteProcessor/OutboundRouteProcessorInterface.php
@@ -17,9 +17,10 @@ interface OutboundRouteProcessorInterface {
   /**
    * Processes the outbound route.
    *
+   * @param string $route_name
+   *   The route name.
    * @param \Symfony\Component\Routing\Route $route
    *   The outbound route to process.
-   *
    * @param array $parameters
    *   An array of parameters to be passed to the route compiler. Passed by
    *   reference.
@@ -27,6 +28,6 @@ interface OutboundRouteProcessorInterface {
    * @return
    *   The processed path.
    */
-  public function processOutbound(Route $route, array &$parameters);
+  public function processOutbound($route_name, Route $route, array &$parameters);
 
 }
diff --git a/core/lib/Drupal/Core/RouteProcessor/RouteProcessorManager.php b/core/lib/Drupal/Core/RouteProcessor/RouteProcessorManager.php
index 3dc8864d773c..049fc7cb9c28 100644
--- a/core/lib/Drupal/Core/RouteProcessor/RouteProcessorManager.php
+++ b/core/lib/Drupal/Core/RouteProcessor/RouteProcessorManager.php
@@ -50,10 +50,10 @@ public function addOutbound(OutboundRouteProcessorInterface $processor, $priorit
   /**
    * {@inheritdoc}
    */
-  public function processOutbound(Route $route, array &$parameters) {
+  public function processOutbound($route_name, Route $route, array &$parameters) {
     $processors = $this->getOutbound();
     foreach ($processors as $processor) {
-      $processor->processOutbound($route, $parameters);
+      $processor->processOutbound($route_name, $route, $parameters);
     }
   }
 
diff --git a/core/lib/Drupal/Core/Routing/NullGenerator.php b/core/lib/Drupal/Core/Routing/NullGenerator.php
index a271538d0d07..6ec6e118568a 100644
--- a/core/lib/Drupal/Core/Routing/NullGenerator.php
+++ b/core/lib/Drupal/Core/Routing/NullGenerator.php
@@ -44,7 +44,7 @@ protected function getRoute($name) {
   /**
    * {@inheritdoc}
    */
-  protected function processRoute(Route $route, array &$parameters) {
+  protected function processRoute($name, Route $route, array &$parameters) {
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php
index ae41c9c4f5fc..ef8d9c9681f0 100644
--- a/core/lib/Drupal/Core/Routing/UrlGenerator.php
+++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
@@ -160,7 +160,7 @@ public function generateFromRoute($name, $parameters = array(), $options = array
     $options += array('prefix' => '');
     $absolute = !empty($options['absolute']);
     $route = $this->getRoute($name);
-    $this->processRoute($route, $parameters);
+    $this->processRoute($name, $route, $parameters);
 
     // Symfony adds any parameters that are not path slugs as query strings.
     if (isset($options['query']) && is_array($options['query'])) {
@@ -331,12 +331,13 @@ protected function processPath($path, &$options = array()) {
    *
    * @param \Symfony\Component\Routing\Route $route
    *   The route object to process.
-   *
    * @param array $parameters
    *   An array of parameters to be passed to the route compiler.
+   * @param string $name
+   *   The route name.
    */
-  protected function processRoute(SymfonyRoute $route, array &$parameters) {
-    $this->routeProcessor->processOutbound($route, $parameters);
+  protected function processRoute($name, SymfonyRoute $route, array &$parameters) {
+    $this->routeProcessor->processOutbound($name, $route, $parameters);
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/Access/RouteProcessorCsrfTest.php b/core/tests/Drupal/Tests/Core/Access/RouteProcessorCsrfTest.php
index 871ffb06aef7..48f77b9c7bf6 100644
--- a/core/tests/Drupal/Tests/Core/Access/RouteProcessorCsrfTest.php
+++ b/core/tests/Drupal/Tests/Core/Access/RouteProcessorCsrfTest.php
@@ -49,7 +49,7 @@ public function testProcessOutboundNoRequirement() {
     $route = new Route('/test-path');
     $parameters = array();
 
-    $this->processor->processOutbound($route, $parameters);
+    $this->processor->processOutbound('test', $route, $parameters);
     // No parameters should be added to the parameters array.
     $this->assertEmpty($parameters);
   }
@@ -67,7 +67,7 @@ public function testProcessOutbound() {
     $route = new Route('/test-path', array(), array('_csrf_token' => 'TRUE'));
     $parameters = array();
 
-    $this->processor->processOutbound($route, $parameters);
+    $this->processor->processOutbound('test', $route, $parameters);
     // 'token' should be added to the parameters array.
     $this->assertArrayHasKey('token', $parameters);
     $this->assertSame($parameters['token'], 'test_token');
@@ -85,7 +85,7 @@ public function testProcessOutboundDynamicOne() {
     $route = new Route('/test-path/{slug}', array(), array('_csrf_token' => 'TRUE'));
     $parameters = array('slug' => 100);
 
-    $this->assertNull($this->processor->processOutbound($route, $parameters));
+    $this->assertNull($this->processor->processOutbound('test', $route, $parameters));
   }
 
   /**
@@ -100,7 +100,7 @@ public function testProcessOutboundDynamicTwo() {
     $route = new Route('{slug_1}/test-path/{slug_2}', array(), array('_csrf_token' => 'TRUE'));
     $parameters = array('slug_1' => 100, 'slug_2' => 'test');
 
-    $this->assertNull($this->processor->processOutbound($route, $parameters));
+    $this->assertNull($this->processor->processOutbound('test', $route, $parameters));
   }
 
 }
diff --git a/core/tests/Drupal/Tests/Core/RouteProcessor/RouteProcessorManagerTest.php b/core/tests/Drupal/Tests/Core/RouteProcessor/RouteProcessorManagerTest.php
index eacc6d8e89de..e002f44fd821 100644
--- a/core/tests/Drupal/Tests/Core/RouteProcessor/RouteProcessorManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/RouteProcessor/RouteProcessorManagerTest.php
@@ -34,11 +34,12 @@ protected function setUp() {
   public function testRouteProcessorManager() {
     $route = new Route('');
     $parameters = array('test' => 'test');
+    $route_name = 'test_name';
 
     $processors = array(
-      10 => $this->getMockProcessor($route, $parameters),
-      5 => $this->getMockProcessor($route, $parameters),
-      0 => $this->getMockProcessor($route, $parameters),
+      10 => $this->getMockProcessor($route_name, $route, $parameters),
+      5 => $this->getMockProcessor($route_name, $route, $parameters),
+      0 => $this->getMockProcessor($route_name, $route, $parameters),
     );
 
     // Add the processors in reverse order.
@@ -46,12 +47,14 @@ public function testRouteProcessorManager() {
       $this->processorManager->addOutbound($processor, $priority);
     }
 
-    $this->processorManager->processOutbound($route, $parameters);
+    $this->processorManager->processOutbound($route_name, $route, $parameters);
   }
 
   /**
    * Returns a mock Route processor object.
    *
+   * @param string $route_name
+   *   The route name.
    * @param \Symfony\Component\Routing\Route $route
    *   The Route to use in mock with() expectation.
    * @param array $parameters
@@ -59,11 +62,11 @@ public function testRouteProcessorManager() {
    *
    * @return \Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
    */
-  protected function getMockProcessor($route, $parameters) {
+  protected function getMockProcessor($route_name, $route, $parameters) {
     $processor = $this->getMock('Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface');
     $processor->expects($this->once())
       ->method('processOutbound')
-      ->with($route, $parameters);
+      ->with($route_name, $route, $parameters);
 
     return $processor;
   }
-- 
GitLab