diff --git a/core/modules/block_place/block_place.libraries.yml b/core/modules/block_place/block_place.libraries.yml index 0671252..7d19419 100644 --- a/core/modules/block_place/block_place.libraries.yml +++ b/core/modules/block_place/block_place.libraries.yml @@ -9,3 +9,11 @@ drupal.block_place.icons: css: theme: css/block-place.icons.theme.css: {} + +drupal.block_place.js: + version: VERSION + js: + js/block_place.js: {} + dependencies: + - outside_in/ drupal.outside_in + diff --git a/core/modules/block_place/block_place.module b/core/modules/block_place/block_place.module index 7fe86a6..9083f75 100644 --- a/core/modules/block_place/block_place.module +++ b/core/modules/block_place/block_place.module @@ -82,3 +82,22 @@ function block_place_toolbar() { ]; return $items; } + +/** + * Implements hook_page_top(). + * + * Add block place library if dialog should be open to sort blocks. + */ +function block_place_page_top(array &$page_top) { + if ($region_sort = \Drupal::request()->query->get('region_sort')) { + $page_top['#attached']['library'][] = 'block_place/drupal.block_place.js'; + $destination = \Drupal::destination()->get(); + $destination = explode('?', $destination)[0]; + $url = Url::fromRoute('block_place.admin_display', ['region' => $region_sort], ['query' => ['destination' => $destination]]); + $page_top['#attached']['drupalSettings']['block_place'] = [ + 'dialog_url' => $url->setAbsolute()->toString(), + 'dialog_type' => \Drupal::moduleHandler()->moduleExists('outside_in') ? 'dialog_offcanvas' : 'modal', + ]; + } +} + diff --git a/core/modules/block_place/block_place.routing.yml b/core/modules/block_place/block_place.routing.yml index 4d7c765..9c4a4d8 100644 --- a/core/modules/block_place/block_place.routing.yml +++ b/core/modules/block_place/block_place.routing.yml @@ -6,3 +6,10 @@ block_place.admin_library: requirements: _access_theme: 'TRUE' _permission: 'administer blocks' +block_place.admin_display: + path: 'admin/structure/block-place/{region}' + defaults: + _controller: '\Drupal\block_place\Controller\BlockPlaceListController::listing' + _title: 'Order Blocks' + requirements: + _permission: 'administer blocks' diff --git a/core/modules/block_place/js/block_place.js b/core/modules/block_place/js/block_place.js new file mode 100644 index 0000000..140b7c5 --- /dev/null +++ b/core/modules/block_place/js/block_place.js @@ -0,0 +1,29 @@ +/** + * @file + * Block Place behaviors. + */ + +(function ($, window, Drupal, drupalSettings) { + + 'use strict'; + + Drupal.behaviors.blockPlace = { + attach: function (context, settings) { + // If drupalSettings.block_place is set open open dialog. + if (drupalSettings.hasOwnProperty('block_place') && drupalSettings.block_place.hasOwnProperty('dialog_url')) { + $(window).once('block_sort').each(function () { + var blockSort = Drupal.ajax({ + dialog: {}, + dialogType: drupalSettings.block_place.dialog_type, + selector: '.ckeditor-dialog-loading-link', + url: drupalSettings.block_place.dialog_url, + progress: {type: 'throbber'} + }); + blockSort.execute(); + }); + } + + } + }; + +})(jQuery, window, Drupal, drupalSettings); diff --git a/core/modules/block_place/src/Controller/BlockPlaceListController.php b/core/modules/block_place/src/Controller/BlockPlaceListController.php new file mode 100644 index 0000000..00e6384 --- /dev/null +++ b/core/modules/block_place/src/Controller/BlockPlaceListController.php @@ -0,0 +1,55 @@ + 'value', + '#value' => $region, + ]; + $rendered['blocks'][$key]['theme'] = [ + '#type' => 'value', + '#value' => $theme, + ]; + } + } + + } + // Unset row to display region name and place a new block. + unset($rendered['blocks']["region-$region"], $rendered['blocks']["region-$region-message"]); + return $rendered; + } + +} diff --git a/core/modules/block_place/src/Controller/PlaceBlockLibraryController.php b/core/modules/block_place/src/Controller/PlaceBlockLibraryController.php index 443336b..9aa2847 100644 --- a/core/modules/block_place/src/Controller/PlaceBlockLibraryController.php +++ b/core/modules/block_place/src/Controller/PlaceBlockLibraryController.php @@ -20,13 +20,22 @@ public function listBlocks(Request $request, $theme) { $build = parent::listBlocks($request, $theme); // Alter all 'Place Block' links to use the Offcanvas tray. if (isset($build['blocks']['#rows'])) { + if ($this->moduleHandler()->moduleExists('outside_in')) { + $data_dialog_attributes = [ + 'data-dialog-type' => 'dialog', + 'data-dialog-renderer' => 'offcanvas', + 'data-dialog-options' => Json::encode([ + 'width' => 425, + ]), + ]; + } + else { + $data_dialog_attributes = []; + } foreach ($build['blocks']['#rows'] as &$row) { if (isset($row['operations']['data']['#links']['add'])) { - $row['operations']['data']['#links']['add']['attributes']['data-dialog-type'] = 'dialog'; - $row['operations']['data']['#links']['add']['attributes']['data-dialog-renderer'] = 'offcanvas'; - $row['operations']['data']['#links']['add']['attributes']['data-dialog-options'] = Json::encode([ - 'width' => 425, - ]); + $row['operations']['data']['#links']['add']['attributes'] = $data_dialog_attributes + $row['operations']['data']['#links']['add']['attributes']; + $row['operations']['data']['#links']['add']['query']['destination'] = \Drupal::destination()->get(); } } } diff --git a/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php b/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php index 8943318..a13a315 100644 --- a/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php +++ b/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php @@ -109,7 +109,7 @@ public function build() { 'region' => $region, ]; if ($destination) { - $query['destination'] = $destination; + $query['destination'] = $destination . "?region_sort=$region"; } $title = $this->t('Place block in the %region region', ['%region' => $region_name]); // @todo Remove module exists check when offcanvas library moved into @@ -134,6 +134,8 @@ public function build() { ]; } + $place_block_route = 'block_place.admin_library'; + $operations['block_description'] = [ '#type' => 'inline_template', '#template' => '
{{ link }}
',