diff --git a/core/modules/views/tests/src/Functional/Wizard/BasicTest.php b/core/modules/views/tests/src/Functional/Wizard/BasicTest.php index 79cf695fedc..cd0b4d7ca7e 100644 --- a/core/modules/views/tests/src/Functional/Wizard/BasicTest.php +++ b/core/modules/views/tests/src/Functional/Wizard/BasicTest.php @@ -176,6 +176,20 @@ class BasicTest extends WizardTestBase { $this->assertEqual(count($data), 1, 'Only the node of type page is exported.'); $node = reset($data); $this->assertEqual($node['nid'][0]['value'], $node1->id(), 'The node of type page is exported.'); + + // Create a view with a leading slash in the path and test that is properly + // set. + $leading_slash_view = []; + $leading_slash_view['label'] = $this->randomMachineName(16); + $leading_slash_view['id'] = strtolower($this->randomMachineName(16)); + $leading_slash_view['description'] = $this->randomMachineName(16); + $leading_slash_view['show[wizard_key]'] = 'node'; + $leading_slash_view['show[type]'] = 'page'; + $leading_slash_view['page[create]'] = 1; + $leading_slash_view['page[title]'] = $this->randomMachineName(16); + $leading_slash_view['page[path]'] = '/' . $this->randomMachineName(16); + $this->drupalPostForm('admin/structure/views/add', $leading_slash_view, t('Save and edit')); + $this->assertEquals($leading_slash_view['page[path]'], $this->cssSelect('#views-page-1-path')[0]->getText()); } /** diff --git a/core/modules/views_ui/src/ViewAddForm.php b/core/modules/views_ui/src/ViewAddForm.php index cfdd4e206e0..37b0136e555 100644 --- a/core/modules/views_ui/src/ViewAddForm.php +++ b/core/modules/views_ui/src/ViewAddForm.php @@ -164,6 +164,13 @@ class ViewAddForm extends ViewFormBase { $wizard_instance = $this->wizardManager->createInstance($wizard_type); $form_state->set('wizard', $wizard_instance->getPluginDefinition()); $form_state->set('wizard_instance', $wizard_instance); + + $path = &$form_state->getValue(['page', 'path']); + if (!empty($path)) { + // @todo https://www.drupal.org/node/2423913 Views should expect and store + // a leading /. + $path = ltrim($path, '/ '); + } $errors = $wizard_instance->validateView($form, $form_state); foreach ($errors as $display_errors) {