Issue #2915772 by andypost, mrinalini9, dawehner, Wim Leers: Deprecate non_lazy_route_enhancer service tag in favor of route_enhancer, same for non_lazy_route_filter and route_filter

merge-requests/3392/head
catch 2023-02-06 21:11:49 +00:00
parent 8fd8edd8f8
commit 8a993aec1a
3 changed files with 63 additions and 2 deletions

View File

@ -1019,9 +1019,9 @@ services:
arguments: ['@router.route_provider', '@path.current', '@url_generator']
tags:
# @todo Try to combine those tags together, see https://www.drupal.org/node/2915772.
- { name: service_collector, tag: non_lazy_route_enhancer, call: addRouteEnhancer }
- { name: service_collector, tag: non_lazy_route_enhancer, call: addDeprecatedRouteEnhancer }
- { name: service_collector, tag: route_enhancer, call: addRouteEnhancer }
- { name: service_collector, tag: non_lazy_route_filter, call: addRouteFilter }
- { name: service_collector, tag: non_lazy_route_filter, call: addDeprecatedRouteFilter }
- { name: service_collector, tag: route_filter, call: addRouteFilter }
calls:
- [setContext, ['@router.request_context']]

View File

@ -84,6 +84,22 @@ class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterf
$this->filters[] = $route_filter;
}
/**
* Adds a deprecated route filter.
*
* @param \Drupal\Core\Routing\FilterInterface $route_filter
* The route filter.
*
* @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use
* route_filter instead.
*
* @see https://www.drupal.org/node/2894934
*/
public function addDeprecatedRouteFilter(FilterInterface $route_filter) {
@trigger_error('non_lazy_route_filter is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use route_filter instead. See https://www.drupal.org/node/2894934', E_USER_DEPRECATED);
$this->filters[] = $route_filter;
}
/**
* Adds a route enhancer.
*
@ -94,6 +110,22 @@ class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterf
$this->enhancers[] = $route_enhancer;
}
/**
* Adds a deprecated route enhancer.
*
* @param \Drupal\Core\Routing\EnhancerInterface $route_enhancer
* The route enhancer.
*
* @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use
* route_enhancer instead.
*
* @see https://www.drupal.org/node/2894934
*/
public function addDeprecatedRouteEnhancer(EnhancerInterface $route_enhancer) {
@trigger_error('non_lazy_route_enhancer is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use route_enhancer instead. See https://www.drupal.org/node/2894934', E_USER_DEPRECATED);
$this->enhancers[] = $route_enhancer;
}
/**
* {@inheritdoc}
*/

View File

@ -3,6 +3,8 @@
namespace Drupal\Tests\Core\Routing;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Routing\EnhancerInterface;
use Drupal\Core\Routing\FilterInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Routing\Router;
use Drupal\Core\Routing\UrlGeneratorInterface;
@ -33,4 +35,31 @@ class RouterUnsupportedTest extends UnitTestCase {
$router->generate($route_name);
}
/**
* @covers ::addDeprecatedRouteFilter
* @covers ::addDeprecatedRouteEnhancer
*/
public function testDeprecatedAdd() {
// Test needs access to router's protected properties.
$filters = new \ReflectionProperty(Router::class, 'filters');
$filters->setAccessible(TRUE);
$enhancers = new \ReflectionProperty(Router::class, 'enhancers');
$enhancers->setAccessible(TRUE);
$route_provider = $this->prophesize(RouteProviderInterface::class);
$current_path_stack = $this->prophesize(CurrentPathStack::class);
$url_generator = $this->prophesize(UrlGeneratorInterface::class);
$router = new Router($route_provider->reveal(), $current_path_stack->reveal(), $url_generator->reveal());
$this->expectDeprecation('non_lazy_route_filter is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use route_filter instead. See https://www.drupal.org/node/2894934');
$filter = $this->prophesize(FilterInterface::class)->reveal();
$router->addDeprecatedRouteFilter($filter);
$this->assertSame($filter, $filters->getValue($router)[0]);
$this->expectDeprecation('non_lazy_route_enhancer is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use route_enhancer instead. See https://www.drupal.org/node/2894934');
$enhancer = $this->prophesize(EnhancerInterface::class)->reveal();
$router->addDeprecatedRouteEnhancer($enhancer);
$this->assertSame($enhancer, $enhancers->getValue($router)[0]);
}
}