diff --git a/core/includes/common.inc b/core/includes/common.inc index 90641b6..11da6d7 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2214,11 +2214,18 @@ function drupal_add_js($data = NULL, $options = NULL) { $scriptPath = $GLOBALS['script_path']; $pathPrefix = ''; url('', array('script' => &$scriptPath, 'prefix' => &$pathPrefix)); + $current_path = current_path(); + $current_path_is_admin = FALSE; + // The function path_is_admin() is not available on update.php pages. + if (!(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE === 'update')) { + $current_path_is_admin = path_is_admin($current_path); + } $javascript['settings']['data'][] = array( 'basePath' => base_path(), 'scriptPath' => $scriptPath, 'pathPrefix' => $pathPrefix, - 'currentPath' => current_path(), + 'currentPath' => $current_path, + 'currentPathIsAdmin' => $current_path_is_admin, ); } // All JavaScript settings are placed in the header of the page with diff --git a/core/modules/block/lib/Drupal/block/Controller/BlockController.php b/core/modules/block/lib/Drupal/block/Controller/BlockController.php index c735ba0..f2ebb41 100644 --- a/core/modules/block/lib/Drupal/block/Controller/BlockController.php +++ b/core/modules/block/lib/Drupal/block/Controller/BlockController.php @@ -30,6 +30,16 @@ public function demo($theme) { return array( '#title' => String::checkPlain($themes[$theme]->info['name']), '#attached' => array( + 'js' => array( + array( + // The block demonstration page is not marked as an administrative + // page by path_is_admin() 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. + 'data' => array('currentPathIsAdmin' => TRUE), + 'type' => 'setting', + ) + ), 'library' => array( array('block', 'drupal.block.admin'), ), diff --git a/core/modules/toolbar/css/toolbar.icons.css b/core/modules/toolbar/css/toolbar.icons.css index b10de97..0d265d6 100644 --- a/core/modules/toolbar/css/toolbar.icons.css +++ b/core/modules/toolbar/css/toolbar.icons.css @@ -319,7 +319,18 @@ background-image: url("../../../misc/icons/787878/twistie-up.png"); background-size: auto auto; } - +.toolbar .toolbar-icon-escape-admin:before { + background-image: url("../../../misc/icons/bebebe/chevron-disc-left.svg"); +} +.no-svg .toolbar .toolbar-icon-escape-admin:before { + background-image: url("../../../misc/icons/bebebe/chevron-disc-left.png"); +} +[dir="rtl"] .toolbar .toolbar-icon-escape-admin:before { + background-image: url("../../../misc/icons/bebebe/chevron-disc-right.svg"); +} +[dir="rtl"] .no-svg .toolbar .toolbar-icon-escape-admin:before { + background-image: url("../../../misc/icons/bebebe/chevron-disc-right.png"); +} /** * Orientation toggle. */ diff --git a/core/modules/toolbar/css/toolbar.module.css b/core/modules/toolbar/css/toolbar.module.css index 279d57b..df76b90 100644 --- a/core/modules/toolbar/css/toolbar.module.css +++ b/core/modules/toolbar/css/toolbar.module.css @@ -38,6 +38,9 @@ .toolbar .menu li { display: block; } +.toolbar .toolbar-bar .toolbar-tab.hidden { + display: none; +} .toolbar a { display: block; line-height: 1; diff --git a/core/modules/toolbar/js/escapeAdmin.js b/core/modules/toolbar/js/escapeAdmin.js new file mode 100644 index 0000000..7c83971 --- /dev/null +++ b/core/modules/toolbar/js/escapeAdmin.js @@ -0,0 +1,53 @@ +/** + * @file + * + * Replaces the home link in toolbar with a back to site link. + */ +(function ($, Drupal, drupalSettings) { + +"use strict"; + +var escapeAdminPath = sessionStorage.getItem('escapeAdminPath'); + +// Saves the last non-administrative page in the browser to be able to link back +// to it when browsing administrative pages. If there is a destination parameter +// there is not need to save the current path because the page is loaded within +// an existing "workflow". +if (!drupalSettings.currentPathIsAdmin && !/destination=/.test(window.location.search)) { + sessionStorage.setItem('escapeAdminPath', drupalSettings.currentPath); +} + +/** + * Replaces the "Home" link with "Back to site" link. + * + * Back to site link points to the last non-administrative page the user visited + * within the same browser tab. + */ +Drupal.behaviors.escapeAdmin = { + attach: function () { + var $toolbarEscape = $('[data-toolbar-escape-admin]').once('escapeAdmin'); + if ($toolbarEscape.length) { + if (drupalSettings.currentPathIsAdmin && escapeAdminPath) { + $toolbarEscape + .removeClass('toolbar-icon-home') + .addClass('toolbar-icon-escape-admin') + .attr({ + 'href': Drupal.url(escapeAdminPath), + 'title': Drupal.t('Return to site content') + }) + .text(Drupal.t('Back to site')); + + $toolbarEscape.closest('.toolbar-tab').removeClass('hidden'); + + // Escape admin when hitting Esc key. + $(window).on('keydown', function (event) { + if (event.keyCode === 27) { + window.location = Drupal.url(escapeAdminPath); + } + }); + } + } + } +}; + +})(jQuery, Drupal, drupalSettings); diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 85bfafa..386df60 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -416,9 +416,18 @@ function toolbar_toolbar() { 'attributes' => array( 'title' => t('Home page'), 'class' => array('toolbar-icon', 'toolbar-icon-home'), + 'data-toolbar-escape-admin' => TRUE, ), ), ), + '#wrapper_attributes' => array( + 'class' => array('hidden'), + ), + '#attached' => array( + 'library' => array( + array('toolbar', 'toolbar.escapeAdmin'), + ), + ), '#weight' => -20, ); @@ -609,6 +618,18 @@ function toolbar_library_info() { array('system', 'jquery.once'), ), ); + $libraries['toolbar.escapeAdmin'] = array( + 'title' => 'Provides a button to escape the administration area.', + 'version' => \Drupal::VERSION, + 'js' => array( + drupal_get_path('module', 'toolbar') . '/js/escapeAdmin.js', + ), + 'dependencies' => array( + array('system', 'jquery'), + array('system', 'drupal'), + array('system', 'drupalSettings'), + ), + ); return $libraries; }