Commit 8e729c32 authored by alexpott's avatar alexpott

Issue #2102417 by damiankloip, dawehner: Change...

Issue #2102417 by damiankloip, dawehner: Change Drupal\Core\Routing\RouteBuildEvent::getModule() to getProvider().
parent 43a4ef25
......@@ -56,7 +56,7 @@ protected function alterRoutes(RouteCollection $collection, $module) {
*/
public function onAlterRoutes(RouteBuildEvent $event) {
$collection = $event->getRouteCollection();
return $this->alterRoutes($collection, $event->getModule());
return $this->alterRoutes($collection, $event->getProvider());
}
}
......@@ -68,8 +68,8 @@ public function addRoutes(RouteCollection $routes) {
* Dumps a set of routes to the router table in the database.
*
* Available options:
* - route_set: The route grouping that is being dumped. All existing
* routes with this route set will be deleted on dump.
* - provider: The route grouping that is being dumped. All existing
* routes with this provider will be deleted on dump.
* - base_class: The base class name.
*
* @param array $options
......@@ -77,13 +77,13 @@ public function addRoutes(RouteCollection $routes) {
*/
public function dump(array $options = array()) {
$options += array(
'route_set' => '',
'provider' => '',
);
// Convert all of the routes into database records.
$insert = $this->connection->insert($this->tableName)->fields(array(
'name',
'route_set',
'provider',
'fit',
'path',
'pattern_outline',
......@@ -96,7 +96,7 @@ public function dump(array $options = array()) {
$compiled = $route->compile();
$values = array(
'name' => $name,
'route_set' => $options['route_set'],
'provider' => $options['provider'],
'fit' => $compiled->getFit(),
'path' => $compiled->getPath(),
'pattern_outline' => $compiled->getPatternOutline(),
......@@ -106,18 +106,18 @@ public function dump(array $options = array()) {
$insert->values($values);
}
// Delete any old records in this route set first, then insert the new ones.
// Delete any old records in this provider first, then insert the new ones.
// That avoids stale data. The transaction makes it atomic to avoid
// unstable router states due to random failures.
$txn = $this->connection->startTransaction();
$this->connection->delete($this->tableName)
->condition('route_set', $options['route_set'])
->condition('provider', $options['provider'])
->execute();
$insert->execute();
// We want to reuse the dumper for multiple route sets, so on dump, flush
// We want to reuse the dumper for multiple providers, so on dump, flush
// the queued routes.
$this->routes = NULL;
......
......@@ -23,18 +23,18 @@ class RouteBuildEvent extends Event {
protected $routeCollection;
/**
* The module name that provides the route.
* The provider of this route collection.
*
* @var string
*/
protected $module;
protected $provider;
/**
* Constructs a RouteBuildEvent object.
*/
public function __construct(RouteCollection $route_collection, $module) {
public function __construct(RouteCollection $route_collection, $provider) {
$this->routeCollection = $route_collection;
$this->module = $module;
$this->provider = $provider;
}
/**
......@@ -45,10 +45,10 @@ public function getRouteCollection() {
}
/**
* Gets the module that provides the route.
* Gets the provider for this route collection.
*/
public function getModule() {
return $this->module;
public function getProvider() {
return $this->provider;
}
}
......@@ -95,7 +95,7 @@ public function rebuild() {
$yaml_discovery = $this->getYamlDiscovery();
foreach ($yaml_discovery->findAll() as $module => $routes) {
foreach ($yaml_discovery->findAll() as $provider => $routes) {
$collection = new RouteCollection();
foreach ($routes as $name => $route_info) {
......@@ -109,9 +109,9 @@ public function rebuild() {
$collection->add($name, $route);
}
$this->dispatcher->dispatch(RoutingEvents::ALTER, new RouteBuildEvent($collection, $module));
$this->dispatcher->dispatch(RoutingEvents::ALTER, new RouteBuildEvent($collection, $provider));
$this->dumper->addRoutes($collection);
$this->dumper->dump(array('route_set' => $module));
$this->dumper->dump(array('provider' => $provider));
}
// Now allow modules to register additional, dynamic routes.
......@@ -119,7 +119,7 @@ public function rebuild() {
$this->dispatcher->dispatch(RoutingEvents::DYNAMIC, new RouteBuildEvent($collection, 'dynamic_routes'));
$this->dispatcher->dispatch(RoutingEvents::ALTER, new RouteBuildEvent($collection, 'dynamic_routes'));
$this->dumper->addRoutes($collection);
$this->dumper->dump(array('route_set' => 'dynamic_routes'));
$this->dumper->dump(array('provider' => 'dynamic_routes'));
$this->lock->release('router_rebuild');
return TRUE;
......
......@@ -20,7 +20,7 @@ abstract class RouteSubscriberBase implements EventSubscriberInterface {
* Provides new routes by adding them to the collection.
*
* Subclasses should use this method and add \Symfony\Component\Routing\Route
* objects with $collection->add($route);.
* objects with $collection->add('route_name', $route);.
*
* @param \Symfony\Component\Routing\RouteCollection $collection
* The route collection for adding routes.
......@@ -33,11 +33,11 @@ protected function routes(RouteCollection $collection) {
*
* @param \Symfony\Component\Routing\RouteCollection $collection
* The route collection for adding routes.
* @param string $module
* The module these routes belong to. For dynamically added routes, the
* module name will be 'dynamic_routes'.
* @param string $provider
* The provider these routes belong to. For dynamically added routes, the
* provider name will be 'dynamic_routes'.
*/
protected function alterRoutes(RouteCollection $collection, $module) {
protected function alterRoutes(RouteCollection $collection, $provider) {
}
/**
......@@ -68,7 +68,7 @@ public function onDynamicRoutes(RouteBuildEvent $event) {
*/
public function onAlterRoutes(RouteBuildEvent $event) {
$collection = $event->getRouteCollection();
$this->alterRoutes($collection, $event->getModule());
$this->alterRoutes($collection, $event->getProvider());
}
}
......@@ -129,7 +129,7 @@ public function testDump() {
$this->fixtures->createTables($connection);
$dumper->dump(array('route_set' => 'test'));
$dumper->dump(array('provider' => 'test'));
$record = $connection->query("SELECT * FROM {test_routes} WHERE name= :name", array(':name' => 'test_route'))->fetchObject();
......
......@@ -962,8 +962,8 @@ function system_schema() {
'not null' => TRUE,
'default' => '',
),
'route_set' => array(
'description' => 'The route set grouping to which a route belongs.',
'provider' => array(
'description' => 'The provider grouping to which a route belongs.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
......@@ -989,7 +989,7 @@ function system_schema() {
),
'indexes' => array(
'pattern_outline_fit' => array('pattern_outline', 'fit'),
'route_set' => array('route_set'),
'provider' => array('provider'),
),
'primary key' => array('name'),
);
......@@ -1620,8 +1620,8 @@ function system_update_8022() {
'not null' => TRUE,
'default' => '',
),
'route_set' => array(
'description' => 'The route set grouping to which a route belongs.',
'provider' => array(
'description' => 'The provider grouping to which a route belongs.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
......@@ -1647,7 +1647,7 @@ function system_update_8022() {
),
'indexes' => array(
'pattern_outline_fit' => array('pattern_outline', 'fit'),
'route_set' => array('route_set'),
'provider' => array('provider'),
),
'primary key' => array('name'),
);
......
......@@ -51,7 +51,7 @@ public function dynamicRoutes(RouteBuildEvent $event) {
* The altered route collection.
*/
public function alterRoutes(RouteBuildEvent $event) {
if ($event->getModule() == 'router_test') {
if ($event->getProvider() == 'router_test') {
$collection = $event->getRouteCollection();
$route = $collection->get('router_test.6');
// Change controller method from test1 to test5.
......
......@@ -172,13 +172,13 @@ public function testRebuildWithStaticModuleRoutes() {
->with($routing_fixtures->sampleRouteCollection());
$this->dumper->expects($this->at(1))
->method('dump')
->with(array('route_set' => 'test_module'));
->with(array('provider' => 'test_module'));
$this->dumper->expects($this->at(2))
->method('addRoutes')
->with($empty_collection);
$this->dumper->expects($this->at(3))
->method('dump')
->with(array('route_set' => 'dynamic_routes'));
->with(array('provider' => 'dynamic_routes'));
$this->assertTrue($this->routeBuilder->rebuild());
......@@ -218,7 +218,7 @@ public function testRebuildWithDynamicRoutes() {
->with($route_collection_filled);
$this->dumper->expects($this->once())
->method('dump')
->with(array('route_set' => 'dynamic_routes'));
->with(array('provider' => 'dynamic_routes'));
$this->assertTrue($this->routeBuilder->rebuild());
}
......
......@@ -175,8 +175,8 @@ public function routingTableDefinition() {
'not null' => TRUE,
'default' => '',
),
'route_set' => array(
'description' => 'The route set grouping to which a route belongs.',
'provider' => array(
'description' => 'The provider grouping to which a route belongs.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
......@@ -215,7 +215,7 @@ public function routingTableDefinition() {
'indexes' => array(
'fit' => array('fit'),
'pattern_outline' => array('pattern_outline'),
'route_set' => array('route_set'),
'provider' => array('provider'),
),
'primary key' => array('name'),
);
......
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