Commit a942dd58 authored by alexpott's avatar alexpott

Issue #2368323 by dawehner, swentel, martin107: Replace _l() in PathController::adminOverview()

parent 9f04e89b
......@@ -505,7 +505,7 @@ services:
- [setContext, ['@?router.request_context']]
unrouted_url_assembler:
class: Drupal\Core\Utility\UnroutedUrlAssembler
arguments: ['@request_stack', '@config.factory' ]
arguments: ['@request_stack', '@config.factory', '@path_processor_manager']
link_generator:
class: Drupal\Core\Utility\LinkGenerator
arguments: ['@url_generator', '@module_handler']
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
......@@ -26,18 +27,28 @@ class UnroutedUrlAssembler implements UnroutedUrlAssemblerInterface {
*/
protected $requestStack;
/**
* The outbound path processor.
*
* @var \Drupal\Core\PathProcessor\OutboundPathProcessorInterface
*/
protected $pathProcessor;
/**
* Constructs a new unroutedUrlAssembler object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The config factory.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* A request stack object.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The config factory.
* @param \Drupal\Core\PathProcessor\OutboundPathProcessorInterface $path_processor
* The output path processor.
*/
public function __construct(RequestStack $request_stack, ConfigFactoryInterface $config) {
public function __construct(RequestStack $request_stack, ConfigFactoryInterface $config, OutboundPathProcessorInterface $path_processor) {
$allowed_protocols = $config->get('system.filter')->get('protocols') ?: ['http', 'https'];
UrlHelper::setAllowedProtocols($allowed_protocols);
$this->requestStack = $request_stack;
$this->pathProcessor = $path_processor;
}
/**
......@@ -99,6 +110,14 @@ protected function buildLocalUrl($uri, array $options = []) {
// Remove the base:// scheme.
$uri = substr($uri, 7);
// Allow (outbound) path processing, if needed. A valid use case is the path
// alias overview form:
// @see \Drupal\path\Controller\PathController::adminOverview().
if (!empty($options['path_processing'])) {
$uri = $this->pathProcessor->processOutbound($uri, $options);
}
// Add any subdirectory where Drupal is installed.
$current_base_path = $request->getBasePath() . '/';
......
......@@ -86,9 +86,10 @@ public function adminOverview(Request $request) {
$destination = drupal_get_destination();
foreach ($this->aliasStorage->getAliasesForAdminListing($header, $keys) as $data) {
$row = array();
$row['data']['alias'] = _l(Unicode::truncate($data->alias, 50, FALSE, TRUE), $data->source, array(
$row['data']['alias'] = $this->l(Unicode::truncate($data->alias, 50, FALSE, TRUE), Url::fromUri('base://' . $data->source, array(
'path_processing' => TRUE,
'attributes' => array('title' => $data->alias),
));
)));
$row['data']['source'] = $this->l(Unicode::truncate($data->source, 50, FALSE, TRUE), Url::fromUri('base://' . $data->source, array(
'alias' => TRUE,
'attributes' => array('title' => $data->source),
......
......@@ -39,6 +39,13 @@ class UnroutedUrlAssemblerTest extends UnitTestCase {
*/
protected $unroutedUrlAssembler;
/**
* The mocked outbound path processor.
*
* @var \Drupal\Core\PathProcessor\OutboundPathProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $pathProcessor;
/**
* {@inheritdoc}
*/
......@@ -47,7 +54,8 @@ protected function setUp() {
$this->requestStack = new RequestStack();
$this->configFactory = $this->getConfigFactoryStub(['system.filter' => []]);
$this->unroutedUrlAssembler = new UnroutedUrlAssembler($this->requestStack, $this->configFactory);
$this->pathProcessor = $this->getMock('Drupal\Core\PathProcessor\OutboundPathProcessorInterface');
$this->unroutedUrlAssembler = new UnroutedUrlAssembler($this->requestStack, $this->configFactory, $this->pathProcessor);
}
/**
......@@ -90,6 +98,56 @@ public function providerTestAssembleWithExternalUrl() {
* @dataProvider providerTestAssembleWithLocalUri
*/
public function testAssembleWithLocalUri($uri, array $options, $subdir, $expected) {
$this->setupRequestStack($subdir);
$this->assertEquals($expected, $this->unroutedUrlAssembler->assemble($uri, $options));
}
/**
* @return array
*/
public function providerTestAssembleWithLocalUri() {
return [
['base://example', [], FALSE, '/example'],
['base://example', ['query' => ['foo' => 'bar']], FALSE, '/example?foo=bar'],
['base://example', ['fragment' => 'example', ], FALSE, '/example#example'],
['base://example', [], TRUE, '/subdir/example'],
['base://example', ['query' => ['foo' => 'bar']], TRUE, '/subdir/example?foo=bar'],
['base://example', ['fragment' => 'example', ], TRUE, '/subdir/example#example'],
];
}
/**
* @covers ::assemble
*/
public function testAssembleWithNotEnabledProcessing() {
$this->setupRequestStack(FALSE);
$this->pathProcessor->expects($this->never())
->method('processOutbound');
$result = $this->unroutedUrlAssembler->assemble('base://test-uri', []);
$this->assertEquals('/test-uri', $result);
}
/**
* @covers ::assemble
*/
public function testAssembleWithEnabledProcessing() {
$this->setupRequestStack(FALSE);
$this->pathProcessor->expects($this->once())
->method('processOutbound')
->with('test-uri', ['path_processing' => TRUE, 'fragment' => NULL, 'query' => [], 'absolute' => NULL, 'prefix' => NULL, 'script' => NULL])
->willReturn('test-other-uri');
$result = $this->unroutedUrlAssembler->assemble('base://test-uri', ['path_processing' => TRUE]);
$this->assertEquals('/test-other-uri', $result);
}
/**
* Setups the request stack for a given subdir.
*
* @param string $subdir
* The wanted subdir.
*/
protected function setupRequestStack($subdir) {
$server = [];
if ($subdir) {
// Setup a fake request which looks like a Drupal installed under the
......@@ -107,23 +165,6 @@ public function testAssembleWithLocalUri($uri, array $options, $subdir, $expecte
}
$request->server->add($server);
$this->requestStack->push($request);
$this->assertEquals($expected, $this->unroutedUrlAssembler->assemble($uri, $options));
}
/**
* @return array
*/
public function providerTestAssembleWithLocalUri() {
return [
['base://example', [], FALSE, '/example'],
['base://example', ['query' => ['foo' => 'bar']], FALSE, '/example?foo=bar'],
['base://example', ['fragment' => 'example', ], FALSE, '/example#example'],
['base://example', [], TRUE, '/subdir/example'],
['base://example', ['query' => ['foo' => 'bar']], TRUE, '/subdir/example?foo=bar'],
['base://example', ['fragment' => 'example', ], TRUE, '/subdir/example#example'],
];
}
}
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