diff --git a/core/modules/block_place/block_place.module b/core/modules/block_place/block_place.module index dc0b7efe29..e7a9c23c8b 100644 --- a/core/modules/block_place/block_place.module +++ b/core/modules/block_place/block_place.module @@ -94,7 +94,8 @@ function block_place_toolbar() { * Add block place library if dialog should be open to sort blocks. */ function block_place_page_attachments(array &$attachments) { - if ($region_sort = \Drupal::request()->query->get('block-place-region-sort')) { + $query = \Drupal::request()->query; + if ($region_sort = $query->get('block-place-region-sort')) { $attachments['#attached']['library'][] = 'block_place/drupal.block_place.js'; $destination = \Drupal::destination()->get(); $destination = explode('?', $destination)[0]; @@ -106,6 +107,8 @@ function block_place_page_attachments(array &$attachments) { 'dialog_type' => \Drupal::moduleHandler()->moduleExists('outside_in') ? 'dialog_off_canvas' : 'modal', ]; } + // Save a setting to flag pages where block_place mode is active. + $attachments['#attached']['drupalSettings']['block_place']['isInBlockPlaceMode'] = ($region_sort || $query->get('block-place')); } /** diff --git a/core/modules/block_place/js/block_place.es6.js b/core/modules/block_place/js/block_place.es6.js index 3d33648a0e..92ef736901 100644 --- a/core/modules/block_place/js/block_place.es6.js +++ b/core/modules/block_place/js/block_place.es6.js @@ -4,11 +4,6 @@ */ (function ($, window, Drupal, drupalSettings) { - - 'use strict'; - - Drupal.blockPlace.isBlockPlaceMode = true; - Drupal.behaviors.blockPlace = { attach(context, settings) { // If drupalSettings.block_place is set open open dialog. diff --git a/core/modules/block_place/js/block_place.js b/core/modules/block_place/js/block_place.js index 6638a3a5c7..3c2d40479b 100644 --- a/core/modules/block_place/js/block_place.js +++ b/core/modules/block_place/js/block_place.js @@ -6,28 +6,16 @@ **/ (function ($, window, Drupal, drupalSettings) { - - 'use strict'; - - Drupal.blockPlace = { - isBlockPlaceMode: function isBlockPlaceMode() { - var queryString = decodeURI(window.location.search); - return (/block-place=1/i.test(queryString) || /block-place-region-sort=/i.test(queryString) - ); - } - }; - Drupal.behaviors.blockPlace = { attach: function attach(context, settings) { if (drupalSettings.hasOwnProperty('block_place') && drupalSettings.block_place.hasOwnProperty('dialog_url')) { $(window).once('block_sort').each(function () { - var blockSort = Drupal.ajax({ + Drupal.ajax({ dialog: {}, dialogType: drupalSettings.block_place.dialog_type, url: drupalSettings.block_place.dialog_url, progress: { type: 'throbber' } - }); - blockSort.execute(); + }).execute(); }); } } diff --git a/core/modules/outside_in/js/outside_in.es6.js b/core/modules/outside_in/js/outside_in.es6.js index 883ee66a33..077ad3bdb0 100644 --- a/core/modules/outside_in/js/outside_in.es6.js +++ b/core/modules/outside_in/js/outside_in.es6.js @@ -3,7 +3,7 @@ * Drupal's Settings Tray library. */ -(function ($, Drupal) { +(function ($, Drupal, drupalSettings) { const blockConfigureSelector = '[data-outside-in-edit]'; const toggleEditSelector = '[data-drupal-outsidein="toggle"]'; const itemsToToggleSelector = '[data-off-canvas-main-canvas], #toolbar-bar, [data-drupal-outsidein="editable"] a, [data-drupal-outsidein="editable"] button'; @@ -194,7 +194,7 @@ const editMode = localStorage.getItem('Drupal.contextualToolbar.isViewing') === 'false'; if (editMode) { // Do turn on edit mode when on block - if (!Drupal.hasOwnProperty('blockPlace') || !Drupal.blockPlace.isBlockPlaceMode()) { + if (!drupalSettings.hasOwnProperty('block_place') || !drupalSettings.block_place.isInBlockPlaceMode) { setEditModeState(true); } } @@ -260,4 +260,4 @@ } }, }); -}(jQuery, Drupal)); +}(jQuery, Drupal, drupalSettings)); diff --git a/core/modules/outside_in/js/outside_in.js b/core/modules/outside_in/js/outside_in.js index 1019eea683..326aff5754 100644 --- a/core/modules/outside_in/js/outside_in.js +++ b/core/modules/outside_in/js/outside_in.js @@ -5,7 +5,7 @@ * @preserve **/ -(function ($, Drupal) { +(function ($, Drupal, drupalSettings) { var blockConfigureSelector = '[data-outside-in-edit]'; var toggleEditSelector = '[data-drupal-outsidein="toggle"]'; var itemsToToggleSelector = '[data-off-canvas-main-canvas], #toolbar-bar, [data-drupal-outsidein="editable"] a, [data-drupal-outsidein="editable"] button'; @@ -116,7 +116,7 @@ attach: function attach() { var editMode = localStorage.getItem('Drupal.contextualToolbar.isViewing') === 'false'; if (editMode) { - if (!Drupal.hasOwnProperty('blockPlace') || !Drupal.blockPlace.isBlockPlaceMode()) { + if (!drupalSettings.hasOwnProperty('block_place') || !drupalSettings.block_place.isInBlockPlaceMode) { setEditModeState(true); } } @@ -168,4 +168,4 @@ } } }); -})(jQuery, Drupal); \ No newline at end of file +})(jQuery, Drupal, drupalSettings); \ No newline at end of file