Issue #2344487 by tim.plunkett, dawehner: Provide special route names for <current> and <none>.
parent
17aac91777
commit
8bd63769fa
|
@ -819,6 +819,14 @@ services:
|
||||||
- { name: path_processor_inbound, priority: 200 }
|
- { name: path_processor_inbound, priority: 200 }
|
||||||
- { name: path_processor_outbound, priority: 200 }
|
- { name: path_processor_outbound, priority: 200 }
|
||||||
arguments: ['@config.factory']
|
arguments: ['@config.factory']
|
||||||
|
path_processor_none:
|
||||||
|
class: Drupal\Core\PathProcessor\PathProcessorNone
|
||||||
|
tags:
|
||||||
|
- { name: path_processor_outbound, priority: 200 }
|
||||||
|
path_processor_current:
|
||||||
|
class: Drupal\Core\PathProcessor\PathProcessorCurrent
|
||||||
|
tags:
|
||||||
|
- { name: path_processor_outbound, priority: 200 }
|
||||||
path_processor_alias:
|
path_processor_alias:
|
||||||
class: Drupal\Core\PathProcessor\PathProcessorAlias
|
class: Drupal\Core\PathProcessor\PathProcessorAlias
|
||||||
tags:
|
tags:
|
||||||
|
|
|
@ -187,6 +187,16 @@ class Drupal {
|
||||||
return static::$container->get('request_stack')->getCurrentRequest();
|
return static::$container->get('request_stack')->getCurrentRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrives the request stack.
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\HttpFoundation\RequestStack
|
||||||
|
* The request stack
|
||||||
|
*/
|
||||||
|
public static function requestStack() {
|
||||||
|
return static::$container->get('request_stack');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the currently active route match object.
|
* Retrieves the currently active route match object.
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Contains \Drupal\Core\PathProcessor\PathProcessorCurrent.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Drupal\Core\PathProcessor;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a path processor to replace <current>.
|
||||||
|
*/
|
||||||
|
class PathProcessorCurrent implements OutboundPathProcessorInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function processOutbound($path, &$options = array(), Request $request = NULL) {
|
||||||
|
if ($path == '%3Ccurrent%3E' && $request) {
|
||||||
|
$request_uri = $request->getRequestUri();
|
||||||
|
|
||||||
|
$current_base_path = $request->getBasePath() . '/';
|
||||||
|
return substr($request_uri, strlen($current_base_path));
|
||||||
|
}
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Contains \Drupal\Core\PathProcessor\PathProcessorNone.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Drupal\Core\PathProcessor;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a path processor to replace <none>.
|
||||||
|
*/
|
||||||
|
class PathProcessorNone implements OutboundPathProcessorInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function processOutbound($path, &$options = array(), Request $request = NULL) {
|
||||||
|
if ($path == '%3Cnone%3E') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -97,7 +97,7 @@ function contact_mail($key, &$message, $params) {
|
||||||
'!site-name' => \Drupal::config('system.site')->get('name'),
|
'!site-name' => \Drupal::config('system.site')->get('name'),
|
||||||
'!subject' => $contact_message->getSubject(),
|
'!subject' => $contact_message->getSubject(),
|
||||||
'!form' => !empty($params['contact_form']) ? $params['contact_form']->label() : NULL,
|
'!form' => !empty($params['contact_form']) ? $params['contact_form']->label() : NULL,
|
||||||
'!form-url' => url(current_path(), array('absolute' => TRUE, 'language' => $language)),
|
'!form-url' => \Drupal::url('<current>', [], ['absolute' => TRUE, 'language' => $language]),
|
||||||
'!sender-name' => user_format_name($sender),
|
'!sender-name' => user_format_name($sender),
|
||||||
);
|
);
|
||||||
if ($sender->isAuthenticated()) {
|
if ($sender->isAuthenticated()) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ function locale_test_locale_translation_projects_alter(&$projects) {
|
||||||
|
|
||||||
// Instead of the default ftp.drupal.org we use the file system of the test
|
// Instead of the default ftp.drupal.org we use the file system of the test
|
||||||
// instance to simulate a remote file location.
|
// instance to simulate a remote file location.
|
||||||
$url = url(NULL, array('absolute' => TRUE));
|
$url = \Drupal::url('<none>', [], ['absolute' => TRUE]);
|
||||||
$remote_url = $url . PublicStream::basePath() . '/remote/';
|
$remote_url = $url . PublicStream::basePath() . '/remote/';
|
||||||
|
|
||||||
// Completely replace the project data with a set of test projects.
|
// Completely replace the project data with a set of test projects.
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Contains \Drupal\system\Tests\PathProcessor\PathProcessorIntegrationTest.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Drupal\system\Tests\PathProcessor;
|
||||||
|
|
||||||
|
use Drupal\simpletest\KernelTestBase;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \Drupal\Core\PathProcessor\PathProcessorCurrent
|
||||||
|
* @group path_processor
|
||||||
|
*/
|
||||||
|
class PathProcessorCurrentIntegrationTest extends KernelTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static $modules = ['system'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->installSchema('system', ['router']);
|
||||||
|
\Drupal::service('router.builder')->rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the output process.
|
||||||
|
*/
|
||||||
|
public function testProcessOutbound() {
|
||||||
|
$request_stack = \Drupal::requestStack();
|
||||||
|
/** @var \Symfony\Component\Routing\RequestContext $request_context */
|
||||||
|
$request_context = \Drupal::service('router.request_context');
|
||||||
|
|
||||||
|
// Test request with subdir on homepage.
|
||||||
|
$server = [
|
||||||
|
'SCRIPT_NAME' => '/subdir/index.php',
|
||||||
|
'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php',
|
||||||
|
'SERVER_NAME' => 'http://www.example.com',
|
||||||
|
];
|
||||||
|
$request = Request::create('/subdir', 'GET', [], [], [], $server);
|
||||||
|
$request_stack->push($request);
|
||||||
|
$request_context->fromRequest($request);
|
||||||
|
$this->assertEqual('/subdir/', \Drupal::url('<current>'));
|
||||||
|
|
||||||
|
// Test request with subdir on other page.
|
||||||
|
$server = [
|
||||||
|
'SCRIPT_NAME' => '/subdir/index.php',
|
||||||
|
'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php',
|
||||||
|
'SERVER_NAME' => 'http://www.example.com',
|
||||||
|
];
|
||||||
|
$request = Request::create('/subdir/node/add', 'GET', [], [], [], $server);
|
||||||
|
$request_stack->push($request);
|
||||||
|
$request_context->fromRequest($request);
|
||||||
|
$this->assertEqual('/subdir/node/add', \Drupal::url('<current>'));
|
||||||
|
|
||||||
|
// Test request without subdir on the homepage.
|
||||||
|
$server = [
|
||||||
|
'SCRIPT_NAME' => '/index.php',
|
||||||
|
'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php',
|
||||||
|
'SERVER_NAME' => 'http://www.example.com',
|
||||||
|
];
|
||||||
|
$request = Request::create('/', 'GET', [], [], [], $server);
|
||||||
|
$request_stack->push($request);
|
||||||
|
$request_context->fromRequest($request);
|
||||||
|
$this->assertEqual('/', \Drupal::url('<current>'));
|
||||||
|
|
||||||
|
// Test request without subdir on other page.
|
||||||
|
$server = [
|
||||||
|
'SCRIPT_NAME' => '/index.php',
|
||||||
|
'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php',
|
||||||
|
'SERVER_NAME' => 'http://www.example.com',
|
||||||
|
];
|
||||||
|
$request = Request::create('/node/add', 'GET', [], [], [], $server);
|
||||||
|
$request_stack->push($request);
|
||||||
|
$request_context->fromRequest($request);
|
||||||
|
$this->assertEqual('/node/add', \Drupal::url('<current>'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Contains \Drupal\system\Tests\PathProcessor\PathProcessorNoneIntegrationTest.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Drupal\system\Tests\PathProcessor;
|
||||||
|
|
||||||
|
use Drupal\simpletest\KernelTestBase;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \Drupal\Core\PathProcessor\PathProcessorNone
|
||||||
|
* @group path_processor
|
||||||
|
*/
|
||||||
|
class PathProcessorNoneIntegrationTest extends KernelTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static $modules = ['system'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->installSchema('system', ['router']);
|
||||||
|
\Drupal::service('router.builder')->rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the output process.
|
||||||
|
*/
|
||||||
|
public function testProcessOutbound() {
|
||||||
|
$request_stack = \Drupal::requestStack();
|
||||||
|
/** @var \Symfony\Component\Routing\RequestContext $request_context */
|
||||||
|
$request_context = \Drupal::service('router.request_context');
|
||||||
|
|
||||||
|
// Test request with subdir on homepage.
|
||||||
|
$server = [
|
||||||
|
'SCRIPT_NAME' => '/subdir/index.php',
|
||||||
|
'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php',
|
||||||
|
'SERVER_NAME' => 'http://www.example.com',
|
||||||
|
];
|
||||||
|
$request = Request::create('/subdir', 'GET', [], [], [], $server);
|
||||||
|
$request_stack->push($request);
|
||||||
|
$request_context->fromRequest($request);
|
||||||
|
$this->assertEqual('/subdir/', \Drupal::url('<none>'));
|
||||||
|
$this->assertEqual('/subdir/#test-fragment', \Drupal::url('<none>', [], ['fragment' => 'test-fragment']));
|
||||||
|
|
||||||
|
// Test request with subdir on other page.
|
||||||
|
$server = [
|
||||||
|
'SCRIPT_NAME' => '/subdir/index.php',
|
||||||
|
'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php',
|
||||||
|
'SERVER_NAME' => 'http://www.example.com',
|
||||||
|
];
|
||||||
|
$request = Request::create('/subdir/node/add', 'GET', [], [], [], $server);
|
||||||
|
$request_stack->push($request);
|
||||||
|
$request_context->fromRequest($request);
|
||||||
|
$this->assertEqual('/subdir/', \Drupal::url('<none>'));
|
||||||
|
$this->assertEqual('/subdir/#test-fragment', \Drupal::url('<none>', [], ['fragment' => 'test-fragment']));
|
||||||
|
|
||||||
|
// Test request without subdir on the homepage.
|
||||||
|
$server = [
|
||||||
|
'SCRIPT_NAME' => '/index.php',
|
||||||
|
'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php',
|
||||||
|
'SERVER_NAME' => 'http://www.example.com',
|
||||||
|
];
|
||||||
|
$request = Request::create('/', 'GET', [], [], [], $server);
|
||||||
|
$request_stack->push($request);
|
||||||
|
$request_context->fromRequest($request);
|
||||||
|
$this->assertEqual('/', \Drupal::url('<none>'));
|
||||||
|
$this->assertEqual('/#test-fragment', \Drupal::url('<none>', [], ['fragment' => 'test-fragment']));
|
||||||
|
|
||||||
|
// Test request without subdir on other page.
|
||||||
|
$server = [
|
||||||
|
'SCRIPT_NAME' => '/index.php',
|
||||||
|
'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php',
|
||||||
|
'SERVER_NAME' => 'http://www.example.com',
|
||||||
|
];
|
||||||
|
$request = Request::create('/node/add', 'GET', [], [], [], $server);
|
||||||
|
$request_stack->push($request);
|
||||||
|
$request_context->fromRequest($request);
|
||||||
|
$this->assertEqual('/', \Drupal::url('<none>'));
|
||||||
|
$this->assertEqual('/#test-fragment', \Drupal::url('<none>', [], ['fragment' => 'test-fragment']));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -352,6 +352,12 @@ system.theme_settings_theme:
|
||||||
requirements:
|
requirements:
|
||||||
_access: 'TRUE'
|
_access: 'TRUE'
|
||||||
|
|
||||||
|
'<none>':
|
||||||
|
path: '<none>'
|
||||||
|
|
||||||
|
'<current>':
|
||||||
|
path: '<current>'
|
||||||
|
|
||||||
system.modules_uninstall:
|
system.modules_uninstall:
|
||||||
path: '/admin/modules/uninstall'
|
path: '/admin/modules/uninstall'
|
||||||
defaults:
|
defaults:
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Drupal\Tests\Core;
|
namespace Drupal\Tests\Core;
|
||||||
|
|
||||||
use Drupal\Tests\UnitTestCase;
|
use Drupal\Tests\UnitTestCase;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the Drupal class.
|
* Tests the Drupal class.
|
||||||
|
@ -131,6 +132,18 @@ class DrupalTest extends UnitTestCase {
|
||||||
$this->assertNotNull(\Drupal::queue('test_queue', TRUE));
|
$this->assertNotNull(\Drupal::queue('test_queue', TRUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the testRequestStack() method.
|
||||||
|
*
|
||||||
|
* @covers ::requestStack
|
||||||
|
*/
|
||||||
|
public function testRequestStack() {
|
||||||
|
$request_stack = new RequestStack();
|
||||||
|
$this->setMockContainerService('request_stack', $request_stack);
|
||||||
|
|
||||||
|
$this->assertSame($request_stack, \Drupal::requestStack());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the keyValue() method.
|
* Tests the keyValue() method.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue