diff --git a/core/core.libraries.yml b/core/core.libraries.yml index 6bccc054bc..dea538bf59 100644 --- a/core/core.libraries.yml +++ b/core/core.libraries.yml @@ -45,7 +45,7 @@ drupalSettings: scriptPath: null pathPrefix: null currentPath: null - currentPathIsAdmin: null + escapeFromAdmin: null isFront: null currentLanguage: null pluralDelimiter: null diff --git a/core/modules/block/src/Controller/BlockController.php b/core/modules/block/src/Controller/BlockController.php index 543ce59038..151b9ddcaf 100644 --- a/core/modules/block/src/Controller/BlockController.php +++ b/core/modules/block/src/Controller/BlockController.php @@ -81,7 +81,7 @@ public function demo($theme) { // function in order to use the frontend theme. Since JavaScript // relies on a proper separation of admin pages, it needs to know this // is an actual administrative page. - 'path' => ['currentPathIsAdmin' => TRUE], + 'path' => ['escapeFromAdmin' => TRUE], ], 'library' => [ 'block/drupal.block.admin', diff --git a/core/modules/layout_builder/src/Element/LayoutBuilder.php b/core/modules/layout_builder/src/Element/LayoutBuilder.php index 0814604bbc..2e8017269a 100644 --- a/core/modules/layout_builder/src/Element/LayoutBuilder.php +++ b/core/modules/layout_builder/src/Element/LayoutBuilder.php @@ -130,7 +130,7 @@ protected function layout(SectionStorageInterface $section_storage) { // it is not marked as an administrative page at the route level even though // it performs an administrative task. Mark this as an administrative page // for JavaScript. - $output['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE; + $output['#attached']['drupalSettings']['path']['escapeFromAdmin'] = TRUE; $output['#type'] = 'container'; $output['#attributes']['id'] = 'layout-builder'; $output['#attributes']['class'][] = 'layout-builder'; diff --git a/core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php b/core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php index 696506e75e..5ade582e24 100644 --- a/core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php +++ b/core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php @@ -193,7 +193,7 @@ public function doBuildForm(array $form, FormStateInterface $form_state, Section } // Mark this as an administrative page for JavaScript ("Back to site" link). - $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE; + $form['#attached']['drupalSettings']['path']['escapeFromAdmin'] = TRUE; return $form; } diff --git a/core/modules/layout_builder/src/Form/ConfigureSectionForm.php b/core/modules/layout_builder/src/Form/ConfigureSectionForm.php index 074901c8a3..9d7fcc12cc 100644 --- a/core/modules/layout_builder/src/Form/ConfigureSectionForm.php +++ b/core/modules/layout_builder/src/Form/ConfigureSectionForm.php @@ -137,7 +137,7 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt $form['#attributes']['data-layout-builder-target-highlight-id'] = $target_highlight_id; // Mark this as an administrative page for JavaScript ("Back to site" link). - $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE; + $form['#attached']['drupalSettings']['path']['escapeFromAdmin'] = TRUE; return $form; } diff --git a/core/modules/layout_builder/src/Form/DiscardLayoutChangesForm.php b/core/modules/layout_builder/src/Form/DiscardLayoutChangesForm.php index 5f49f298a8..83628b594a 100644 --- a/core/modules/layout_builder/src/Form/DiscardLayoutChangesForm.php +++ b/core/modules/layout_builder/src/Form/DiscardLayoutChangesForm.php @@ -88,7 +88,7 @@ public function getCancelUrl() { public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL) { $this->sectionStorage = $section_storage; // Mark this as an administrative page for JavaScript ("Back to site" link). - $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE; + $form['#attached']['drupalSettings']['path']['escapeFromAdmin'] = TRUE; return parent::buildForm($form, $form_state); } diff --git a/core/modules/layout_builder/src/Form/LayoutBuilderDisableForm.php b/core/modules/layout_builder/src/Form/LayoutBuilderDisableForm.php index 1b30ca932c..8a8dcb12b6 100644 --- a/core/modules/layout_builder/src/Form/LayoutBuilderDisableForm.php +++ b/core/modules/layout_builder/src/Form/LayoutBuilderDisableForm.php @@ -93,7 +93,7 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt $this->sectionStorage = $section_storage; // Mark this as an administrative page for JavaScript ("Back to site" link). - $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE; + $form['#attached']['drupalSettings']['path']['escapeFromAdmin'] = TRUE; return parent::buildForm($form, $form_state); } diff --git a/core/modules/layout_builder/src/Form/LayoutRebuildConfirmFormBase.php b/core/modules/layout_builder/src/Form/LayoutRebuildConfirmFormBase.php index 9d553730fd..3de496ef53 100644 --- a/core/modules/layout_builder/src/Form/LayoutRebuildConfirmFormBase.php +++ b/core/modules/layout_builder/src/Form/LayoutRebuildConfirmFormBase.php @@ -87,7 +87,7 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt } // Mark this as an administrative page for JavaScript ("Back to site" link). - $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE; + $form['#attached']['drupalSettings']['path']['escapeFromAdmin'] = TRUE; return $form; } diff --git a/core/modules/layout_builder/src/Form/RevertOverridesForm.php b/core/modules/layout_builder/src/Form/RevertOverridesForm.php index c852504f5c..59c3462dc6 100644 --- a/core/modules/layout_builder/src/Form/RevertOverridesForm.php +++ b/core/modules/layout_builder/src/Form/RevertOverridesForm.php @@ -100,7 +100,7 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt $this->sectionStorage = $section_storage; // Mark this as an administrative page for JavaScript ("Back to site" link). - $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE; + $form['#attached']['drupalSettings']['path']['escapeFromAdmin'] = TRUE; return parent::buildForm($form, $form_state); } diff --git a/core/modules/system/src/Controller/Http4xxController.php b/core/modules/system/src/Controller/Http4xxController.php index ee8a9776d4..1a3db7e0b7 100644 --- a/core/modules/system/src/Controller/Http4xxController.php +++ b/core/modules/system/src/Controller/Http4xxController.php @@ -54,6 +54,12 @@ public function on403() { public function on404() { return [ '#markup' => $this->t('The requested page could not be found.'), + '#attached' => [ + 'drupalSettings' => [ + // Do not save this page in as a non-admin page to go back to. + 'path' => ['escapeFromAdmin' => TRUE], + ], + ], ]; } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 064afafbce..adc74678a0 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -712,7 +712,7 @@ function system_js_settings_alter(&$settings, AttachedAssetsInterface $assets) { 'baseUrl' => $request->getBaseUrl() . '/', 'pathPrefix' => $pathPrefix, 'currentPath' => $current_path, - 'currentPathIsAdmin' => $current_path_is_admin, + 'escapeFromAdmin' => $current_path_is_admin, 'isFront' => \Drupal::service('path.matcher')->isFrontPage(), 'currentLanguage' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(), ]; diff --git a/core/modules/system/tests/src/Functional/System/AccessDeniedTest.php b/core/modules/system/tests/src/Functional/System/AccessDeniedTest.php index e580893d08..a5c4ab1e12 100644 --- a/core/modules/system/tests/src/Functional/System/AccessDeniedTest.php +++ b/core/modules/system/tests/src/Functional/System/AccessDeniedTest.php @@ -61,7 +61,7 @@ public function testAccessDenied() { $settings = $this->getDrupalSettings(); $this->assertEqual($settings['path']['currentPath'], 'admin'); - $this->assertEqual($settings['path']['currentPathIsAdmin'], TRUE); + $this->assertEqual($settings['path']['escapeFromAdmin'], TRUE); $this->assertEqual($settings['path']['currentQuery'], ['foo' => 'bar']); $this->drupalLogin($this->adminUser); diff --git a/core/modules/system/tests/src/Functional/System/PageNotFoundTest.php b/core/modules/system/tests/src/Functional/System/PageNotFoundTest.php index 537b1ec717..534cb7c261 100644 --- a/core/modules/system/tests/src/Functional/System/PageNotFoundTest.php +++ b/core/modules/system/tests/src/Functional/System/PageNotFoundTest.php @@ -48,7 +48,9 @@ protected function setUp(): void { public function testPageNotFound() { $this->drupalLogin($this->adminUser); $this->drupalGet($this->randomMachineName(10)); + $settings = $this->getDrupalSettings(); $this->assertText(t('Page not found'), 'Found the default 404 page'); + $this->assertEqual($settings['path']['escapeFromAdmin'], TRUE); // Set a custom 404 page without a starting slash. $edit = [ diff --git a/core/modules/toolbar/js/escapeAdmin.es6.js b/core/modules/toolbar/js/escapeAdmin.es6.js index c91c9d847c..5e3540ac19 100644 --- a/core/modules/toolbar/js/escapeAdmin.es6.js +++ b/core/modules/toolbar/js/escapeAdmin.es6.js @@ -13,7 +13,7 @@ // parameter there is not need to save the current path because the page is // loaded within an existing "workflow". if ( - !pathInfo.currentPathIsAdmin && + !pathInfo.escapeFromAdmin && !/destination=/.test(windowLocation.search) ) { sessionStorage.setItem('escapeAdminPath', windowLocation); @@ -35,7 +35,7 @@ const $toolbarEscape = $('[data-toolbar-escape-admin]').once( 'escapeAdmin', ); - if ($toolbarEscape.length && pathInfo.currentPathIsAdmin) { + if ($toolbarEscape.length && pathInfo.escapeFromAdmin) { if (escapeAdminPath !== null) { $toolbarEscape.attr('href', escapeAdminPath); } else { diff --git a/core/modules/toolbar/js/escapeAdmin.js b/core/modules/toolbar/js/escapeAdmin.js index 0c469c2a43..dce7c3911e 100644 --- a/core/modules/toolbar/js/escapeAdmin.js +++ b/core/modules/toolbar/js/escapeAdmin.js @@ -10,7 +10,7 @@ var escapeAdminPath = sessionStorage.getItem('escapeAdminPath'); var windowLocation = window.location; - if (!pathInfo.currentPathIsAdmin && !/destination=/.test(windowLocation.search)) { + if (!pathInfo.escapeFromAdmin && !/destination=/.test(windowLocation.search)) { sessionStorage.setItem('escapeAdminPath', windowLocation); } @@ -18,7 +18,7 @@ attach: function attach() { var $toolbarEscape = $('[data-toolbar-escape-admin]').once('escapeAdmin'); - if ($toolbarEscape.length && pathInfo.currentPathIsAdmin) { + if ($toolbarEscape.length && pathInfo.escapeFromAdmin) { if (escapeAdminPath !== null) { $toolbarEscape.attr('href', escapeAdminPath); } else { diff --git a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php index b41d7ec7a8..f039929934 100644 --- a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php +++ b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php @@ -210,7 +210,7 @@ public function testSettings() { $this->assertTrue(isset($parsed_settings['path']['baseUrl']), 'drupalSettings.path.baseUrl 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->assertFalse($parsed_settings['path']['currentPathIsAdmin'], 'drupalSettings.path.currentPathIsAdmin is present and has the correct value.'); + $this->assertFalse($parsed_settings['path']['escapeFromAdmin'], 'drupalSettings.path.escapeFromAdmin is present and has the correct value.'); $this->assertFalse($parsed_settings['path']['isFront'], 'drupalSettings.path.isFront is present and has the correct value.'); $this->assertIdentical($parsed_settings['path']['currentLanguage'], 'en', 'drupalSettings.path.currentLanguage is present and has the correct value.');