Commit 95231195 authored by alexpott's avatar alexpott

Issue #2051877 by dawehner, sun, tstoeckler: Log error when people use invalid route parameters.

parent b0152299
...@@ -33,16 +33,12 @@ protected function alterRoutes(RouteCollection $collection) { ...@@ -33,16 +33,12 @@ protected function alterRoutes(RouteCollection $collection) {
'_content', '_content',
'_form', '_form',
); );
foreach ($collection->all() as $name => $route) {
foreach ($collection->all() as $route) {
if ($not_allowed_variables = array_intersect($route->compile()->getVariables(), $special_variables)) { if ($not_allowed_variables = array_intersect($route->compile()->getVariables(), $special_variables)) {
$placeholders = array('@variables' => implode(', ', $not_allowed_variables)); $reserved = implode(', ', $not_allowed_variables);
drupal_set_message(String::format('The following variables are reserved names by drupal: @variables', $placeholders)); trigger_error(sprintf('Route %s uses reserved variable names: %s', $name, $reserved), E_USER_WARNING);
watchdog('error', 'The following variables are reserved names by drupal: @variables', $placeholders);
return FALSE;
} }
} }
return TRUE;
} }
/** /**
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\Core\EventSubscriber\SpecialAttributesRouteSubscriberTest. * Contains \Drupal\Tests\Core\EventSubscriber\SpecialAttributesRouteSubscriberTest.
*/ */
namespace Drupal\Tests\Core\EventSubscriber { namespace Drupal\Tests\Core\EventSubscriber;
use Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber; use Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber;
use Drupal\Core\Routing\RouteBuildEvent; use Drupal\Core\Routing\RouteBuildEvent;
...@@ -85,7 +85,7 @@ public function testOnRouteBuildingValidVariables(Route $route) { ...@@ -85,7 +85,7 @@ public function testOnRouteBuildingValidVariables(Route $route) {
$route_collection = new RouteCollection(); $route_collection = new RouteCollection();
$route_collection->add('test', $route); $route_collection->add('test', $route);
$event = new RouteBuildEvent($route_collection, 'test'); $event = new RouteBuildEvent($route_collection, 'test');
$this->assertTrue($this->specialAttributesRouteSubscriber->onAlterRoutes($event)); $this->specialAttributesRouteSubscriber->onAlterRoutes($event);
} }
/** /**
...@@ -95,25 +95,14 @@ public function testOnRouteBuildingValidVariables(Route $route) { ...@@ -95,25 +95,14 @@ public function testOnRouteBuildingValidVariables(Route $route) {
* The route to check. * The route to check.
* *
* @dataProvider providerTestOnRouteBuildingInvalidVariables * @dataProvider providerTestOnRouteBuildingInvalidVariables
* @expectedException \PHPUnit_Framework_Error_Warning
* @expectedExceptionMessage uses reserved variable names
*/ */
public function testOnRouteBuildingInvalidVariables(Route $route) { public function testOnRouteBuildingInvalidVariables(Route $route) {
$route_collection = new RouteCollection(); $route_collection = new RouteCollection();
$route_collection->add('test', $route); $route_collection->add('test', $route);
$event = new RouteBuildEvent($route_collection, 'test'); $event = new RouteBuildEvent($route_collection, 'test');
$this->assertFalse($this->specialAttributesRouteSubscriber->onAlterRoutes($event)); $this->specialAttributesRouteSubscriber->onAlterRoutes($event);
} }
} }
}
namespace {
if (!function_exists('watchdog')) {
function watchdog($type, $message, array $args = array()) {
}
}
if (!function_exists('drupal_set_message')) {
function drupal_set_message($type = NULL, $message = '') {
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment