Commit ca004120 authored by catch's avatar catch

Issue #2527846 by dawehner, Wim Leers: Try to get rid of Url::fromRoute() in...

Issue #2527846 by dawehner, Wim Leers: Try to get rid of Url::fromRoute() in system_js_settings_alter()
parent 04564f7d
......@@ -46,6 +46,8 @@ public function register(ContainerBuilder $container) {
$container
->register('url_generator', 'Drupal\Core\Routing\NullGenerator')
->addArgument(new Reference('request_stack'));
$container
->register('path_processor_manager', 'Drupal\Core\PathProcessor\NullPathProcessorManager');
$container
->register('router.dumper', 'Drupal\Core\Routing\NullMatcherDumper');
......
<?php
/**
* @file
* Contains \Drupal\Core\PathProcessor\NullPathProcessorManager.
*/
namespace Drupal\Core\PathProcessor;
use Drupal\Core\Render\BubbleableMetadata;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a null implementation of the path processor manager.
*
* This can be used for example in really early installer phases.
*/
class NullPathProcessorManager implements InboundPathProcessorInterface, OutboundPathProcessorInterface {
/**
* {@inheritdoc}
*/
public function processInbound($path, Request $request) {
return $path;
}
/**
* {@inheritdoc}
*/
public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
return $path;
}
}
......@@ -215,7 +215,6 @@ function testSettings() {
// Test whether the settings for core/drupalSettings are available.
$this->assertTrue(isset($parsed_settings['path']['baseUrl']), 'drupalSettings.path.baseUrl is present.');
$this->assertTrue(isset($parsed_settings['path']['scriptPath']), 'drupalSettings.path.scriptPath is present.');
$this->assertIdentical($parsed_settings['path']['pathPrefix'], 'yarhar', 'drupalSettings.path.pathPrefix is present and has the correct (overridden) value.');
$this->assertIdentical($parsed_settings['path']['currentPath'], '', 'drupalSettings.path.currentPath is present and has the correct value.');
$this->assertIdentical($parsed_settings['path']['currentPathIsAdmin'], FALSE, 'drupalSettings.path.currentPathIsAdmin is present and has the correct value.');
......
......@@ -648,21 +648,20 @@ function system_js_settings_build(&$settings, AttachedAssetsInterface $assets) {
* as well as theme_token ajax state.
*/
function system_js_settings_alter(&$settings, AttachedAssetsInterface $assets) {
// url() generates the script and prefix using hook_url_outbound_alter().
// Instead of running the hook_url_outbound_alter() again here, extract
// them from url().
// @todo Make this less hacky: https://www.drupal.org/node/1547376.
$request = \Drupal::request();
$scriptPath = $request->getScriptName();
$pathPrefix = '';
$current_query = $request->query->all();
Url::fromRoute('<front>', [], array('script' => &$scriptPath, 'prefix' => &$pathPrefix))->toString(TRUE);
// Let output path processors set a prefix.
/** @var \Drupal\Core\PathProcessor\OutboundPathProcessorInterface $path_processor */
$path_processor = \Drupal::service('path_processor_manager');
$options = ['prefix' => ''];
$path_processor->processOutbound('/', $options);
$pathPrefix = $options['prefix'];
$current_path = \Drupal::routeMatch()->getRouteName() ? Url::fromRouteMatch(\Drupal::routeMatch())->getInternalPath() : '';
$current_path_is_admin = \Drupal::service('router.admin_context')->isAdminRoute();
$path_settings = [
'baseUrl' => $request->getBaseUrl() . '/',
'scriptPath' => $scriptPath,
'pathPrefix' => $pathPrefix,
'currentPath' => $current_path,
'currentPathIsAdmin' => $current_path_is_admin,
......
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