Commit b4dba2ba authored by alexpott's avatar alexpott

Issue #2236207 by znerol: Use router request context instead of request...

Issue #2236207 by znerol: Use router request context instead of request service in system breadcrumb builder.
parent 775184ce
......@@ -18,6 +18,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
......@@ -27,11 +28,11 @@
class PathBasedBreadcrumbBuilder extends BreadcrumbBuilderBase {
/**
* The current request.
* The router request context.
*
* @var \Symfony\Component\HttpFoundation\Request
* @var \Symfony\Component\Routing\RequestContext
*/
protected $request;
protected $context;
/**
* The menu link access service.
......@@ -78,8 +79,8 @@ class PathBasedBreadcrumbBuilder extends BreadcrumbBuilderBase {
/**
* Constructs the PathBasedBreadcrumbBuilder.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current Request object.
* @param \Symfony\Component\Routing\RequestContext $context
* The router request context.
* @param \Drupal\Core\Access\AccessManager $access_manager
* The menu link access service.
* @param \Symfony\Component\Routing\Matcher\RequestMatcherInterface $router
......@@ -93,8 +94,8 @@ class PathBasedBreadcrumbBuilder extends BreadcrumbBuilderBase {
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user object.
*/
public function __construct(Request $request, AccessManager $access_manager, RequestMatcherInterface $router, InboundPathProcessorInterface $path_processor, ConfigFactoryInterface $config_factory, TitleResolverInterface $title_resolver, AccountInterface $current_user) {
$this->request = $request;
public function __construct(RequestContext $context, AccessManager $access_manager, RequestMatcherInterface $router, InboundPathProcessorInterface $path_processor, ConfigFactoryInterface $config_factory, TitleResolverInterface $title_resolver, AccountInterface $current_user) {
$this->context = $context;
$this->accessManager = $access_manager;
$this->router = $router;
$this->pathProcessor = $path_processor;
......@@ -119,7 +120,7 @@ public function build(array $attributes) {
// General path-based breadcrumbs. Use the actual request path, prior to
// resolving path aliases, so the breadcrumb can be defined by simply
// creating a hierarchy of path aliases.
$path = trim($this->request->getPathInfo(), '/');
$path = trim($this->context->getPathInfo(), '/');
$path_elements = explode('/', $path);
$exclude = array();
// Don't show a link to the front-page path.
......@@ -178,7 +179,7 @@ protected function getRequestForPath($path, array $exclude) {
}
// @todo Use the RequestHelper once https://drupal.org/node/2090293 is
// fixed.
$request = Request::create($this->request->getBaseUrl() . '/' . $path);
$request = Request::create($this->context->getBaseUrl() . '/' . $path);
// Performance optimization: set a short accept header to reduce overhead in
// AcceptHeaderMatcher when matching the request.
$request->headers->set('Accept', 'text/html');
......
......@@ -8,7 +8,7 @@ services:
arguments: ['@module_handler', '@database', '@entity.manager', '@request_stack']
system.breadcrumb.default:
class: Drupal\system\PathBasedBreadcrumbBuilder
arguments: ['@request', '@access_manager', '@router', '@path_processor_manager', '@config.factory', '@title_resolver', '@current_user']
arguments: ['@router.request_context', '@access_manager', '@router', '@path_processor_manager', '@config.factory', '@title_resolver', '@current_user']
tags:
- { name: breadcrumb_builder, priority: 0 }
path_processor.files:
......
......@@ -15,6 +15,7 @@
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
/**
......@@ -56,11 +57,11 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase {
protected $requestMatcher;
/**
* The mocked request object.
* The mocked route request context.
*
* @var \Symfony\Component\HttpFoundation\Request|\PHPUnit_Framework_MockObject_MockObject
* @var \Symfony\Component\Routing\RequestContext|\PHPUnit_Framework_MockObject_MockObject
*/
protected $request;
protected $context;
/**
* The mocked link generator.
......@@ -107,14 +108,14 @@ public function setUp() {
$config_factory = $this->getConfigFactoryStub(array('system.site' => array('front' => 'test_frontpage')));
$this->pathProcessor = $this->getMock('\Drupal\Core\PathProcessor\InboundPathProcessorInterface');
$this->request = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Request')->disableOriginalConstructor()->getMock();
$this->context = $this->getMock('\Symfony\Component\Routing\RequestContext');
$this->accessManager = $this->getMockBuilder('\Drupal\Core\Access\AccessManager')
->disableOriginalConstructor()->getMock();
$this->titleResolver = $this->getMock('\Drupal\Core\Controller\TitleResolverInterface');
$this->currentUser = $this->getMock('Drupal\Core\Session\AccountInterface');
$this->builder = new TestPathBasedBreadcrumbBuilder(
$this->request,
$this->context,
$this->accessManager,
$this->requestMatcher,
$this->pathProcessor,
......@@ -135,7 +136,7 @@ public function setUp() {
* @covers ::build()
*/
public function testBuildOnFrontpage() {
$this->request->expects($this->once())
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/'));
......@@ -149,7 +150,7 @@ public function testBuildOnFrontpage() {
* @covers ::build()
*/
public function testBuildWithOnePathElement() {
$this->request->expects($this->once())
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/example'));
......@@ -166,7 +167,7 @@ public function testBuildWithOnePathElement() {
* @covers ::getRequestForPath()
*/
public function testBuildWithTwoPathElements() {
$this->request->expects($this->once())
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/example/baz'));
$this->setupStubPathProcessor();
......@@ -208,7 +209,7 @@ public function testBuildWithTwoPathElements() {
* @covers ::getRequestForPath()
*/
public function testBuildWithThreePathElements() {
$this->request->expects($this->once())
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/example/bar/baz'));
$this->setupStubPathProcessor();
......@@ -266,7 +267,7 @@ public function testBuildWithThreePathElements() {
* @dataProvider providerTestBuildWithException
*/
public function testBuildWithException($exception_class, $exception_argument) {
$this->request->expects($this->once())
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/example/bar'));
$this->setupStubPathProcessor();
......@@ -305,7 +306,7 @@ public function providerTestBuildWithException() {
* @covers ::getRequestForPath()
*/
public function testBuildWithNonProcessedPath() {
$this->request->expects($this->once())
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/example/bar'));
......@@ -340,7 +341,7 @@ public function testApplies() {
* @covers ::getRequestForPath()
*/
public function testBuildWithUserPath() {
$this->request->expects($this->once())
$this->context->expects($this->once())
->method('getPathInfo')
->will($this->returnValue('/user/1/edit'));
$this->setupStubPathProcessor();
......
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