diff --git a/core/core.services.yml b/core/core.services.yml index 3e2feb6..9b289ed 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -498,7 +498,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'] diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 0da2d40..c3f15db 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -183,8 +183,6 @@ function install_state_defaults() { 'config_verified' => FALSE, // TRUE when there is a valid database connection. 'database_verified' => FALSE, - // TRUE if database is empty & ready to install. - 'database_ready' => FALSE, // TRUE when a valid settings.php exists (containing both database // connection information and config directory names). 'settings_verified' => FALSE, @@ -337,6 +335,9 @@ function install_begin_request($class_loader, &$install_state) { $container ->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager') ->addArgument(new Reference('language_manager')); + $container + ->register('path.matcher', 'Drupal\Core\Path\PathMatcher') + ->addArgument(new Reference('config.factory')); // Register the stream wrapper manager. $container @@ -351,13 +352,6 @@ function install_begin_request($class_loader, &$install_state) { $install_state['database_verified'] = install_verify_database_settings(); $install_state['settings_verified'] = $install_state['config_verified'] && $install_state['database_verified']; - // Install factory tables only after checking the database. - if ($install_state['database_verified'] && $install_state['database_ready']) { - $container - ->register('path.matcher', 'Drupal\Core\Path\PathMatcher') - ->addArgument(new Reference('config.factory')); - } - if ($install_state['settings_verified']) { try { $system_schema = system_schema(); @@ -710,9 +704,6 @@ function install_tasks($install_state) { 'run' => $install_state['settings_verified'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED, 'function' => 'Drupal\Core\Installer\Form\SiteSettingsForm', ), - 'install_verify_database_ready' => array( - 'run' => $install_state['database_ready'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED, - ), 'install_base_system' => array( 'run' => $install_state['base_system_verified'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED, ), @@ -1060,21 +1051,6 @@ function install_verify_database_settings() { } /** - * Verify that the database is ready (no existing Drupal installation). - */ -function install_verify_database_ready() { - $system_schema = system_schema(); - end($system_schema); - $table = key($system_schema); - - if ($database = Database::getConnectionInfo()) { - if (Database::getConnection()->schema()->tableExists($table)) { - throw new AlreadyInstalledException(\Drupal::service('string_translation')); - } - } -} - -/** * Checks a database connection and returns any errors. */ function install_database_errors($database, $settings_file) { diff --git a/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php index 08d0083..2ed2602 100644 --- a/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php +++ b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php @@ -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; /** @@ -27,17 +28,27 @@ class UnroutedUrlAssembler implements UnroutedUrlAssemblerInterface { protected $requestStack; /** + * The output 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 path processing, if needed. + // A valid usecase 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() . '/'; diff --git a/core/modules/path/src/Controller/PathController.php b/core/modules/path/src/Controller/PathController.php index 6d94deb..63b12f1 100644 --- a/core/modules/path/src/Controller/PathController.php +++ b/core/modules/path/src/Controller/PathController.php @@ -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), diff --git a/core/modules/system/src/Tests/Installer/InstallerExistingInstallationTest.php b/core/modules/system/src/Tests/Installer/InstallerExistingInstallationTest.php deleted file mode 100644 index 08198db..0000000 --- a/core/modules/system/src/Tests/Installer/InstallerExistingInstallationTest.php +++ /dev/null @@ -1,44 +0,0 @@ -drupalGet($GLOBALS['base_url'] . '/core/install.php'); - $this->assertRaw('Drupal already installed'); - - // Delete settings.php and attempt to reinstall again. - unlink($this->siteDirectory . '/settings.php'); - $this->drupalGet($GLOBALS['base_url'] . '/core/install.php'); - $this->setUpLanguage(); - $this->setUpProfile(); - $this->setUpSettings(); - $this->assertRaw('Drupal already installed'); - } - -} diff --git a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php index 1790aef..948e91b 100644 --- a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php @@ -40,6 +40,13 @@ class UnroutedUrlAssemblerTest extends UnitTestCase { protected $unroutedUrlAssembler; /** + * The mocked path processor. + * + * @var \Drupal\Core\PathProcessor\OutboundPathProcessorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $pathProcessor; + + /** * {@inheritdoc} */ protected function setUp() { @@ -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'], - ]; } } -