diff --git a/core/modules/layout_builder/js/layout-builder.es6.js b/core/modules/layout_builder/js/layout-builder.es6.js index 391e462cc677542be9d0258cee1fced3abd9558c..cdb5bee76299a4604b55a404a6856e78a554cfee 100644 --- a/core/modules/layout_builder/js/layout-builder.es6.js +++ b/core/modules/layout_builder/js/layout-builder.es6.js @@ -14,15 +14,19 @@ * An object containing information about the item being sorted. */ update(event, ui) { - // Only process if the item was moved from one region to another. - if (ui.sender) { + // Check if the region from the event and region for the item match. + const itemRegion = ui.item.closest('.layout-builder--layout__region'); + if (event.target === itemRegion[0]) { + // Find the destination delta. + const deltaTo = ui.item.closest('[data-layout-delta]').data('layout-delta'); + // If the block didn't leave the original delta use the destination. + const deltaFrom = ui.sender ? ui.sender.closest('[data-layout-delta]').data('layout-delta') : deltaTo; ajax({ url: [ ui.item.closest('[data-layout-update-url]').data('layout-update-url'), - ui.sender.closest('[data-layout-delta]').data('layout-delta'), - ui.item.closest('[data-layout-delta]').data('layout-delta'), - ui.sender.data('region'), - $(this).data('region'), + deltaFrom, + deltaTo, + itemRegion.data('region'), ui.item.data('layout-block-uuid'), ui.item.prev('[data-layout-block-uuid]').data('layout-block-uuid'), ] diff --git a/core/modules/layout_builder/js/layout-builder.js b/core/modules/layout_builder/js/layout-builder.js index d4dadc89344ca9c9e125db695444ca65a7314df1..661c5e3d841bcd2a3afcba97e0d549bf091960ad 100644 --- a/core/modules/layout_builder/js/layout-builder.js +++ b/core/modules/layout_builder/js/layout-builder.js @@ -16,9 +16,13 @@ connectWith: '.layout-builder--layout__region', update: function update(event, ui) { - if (ui.sender) { + var itemRegion = ui.item.closest('.layout-builder--layout__region'); + if (event.target === itemRegion[0]) { + var deltaTo = ui.item.closest('[data-layout-delta]').data('layout-delta'); + + var deltaFrom = ui.sender ? ui.sender.closest('[data-layout-delta]').data('layout-delta') : deltaTo; ajax({ - url: [ui.item.closest('[data-layout-update-url]').data('layout-update-url'), ui.sender.closest('[data-layout-delta]').data('layout-delta'), ui.item.closest('[data-layout-delta]').data('layout-delta'), ui.sender.data('region'), $(this).data('region'), ui.item.data('layout-block-uuid'), ui.item.prev('[data-layout-block-uuid]').data('layout-block-uuid')].filter(function (element) { + url: [ui.item.closest('[data-layout-update-url]').data('layout-update-url'), deltaFrom, deltaTo, itemRegion.data('region'), ui.item.data('layout-block-uuid'), ui.item.prev('[data-layout-block-uuid]').data('layout-block-uuid')].filter(function (element) { return element !== undefined; }).join('/') }).execute(); diff --git a/core/modules/layout_builder/layout_builder.routing.yml b/core/modules/layout_builder/layout_builder.routing.yml index 085eb301114b169fb6afa0dd4b7c3c8a9b0754e2..98465538625e108da9f8bf1f80c133b4984cabdb 100644 --- a/core/modules/layout_builder/layout_builder.routing.yml +++ b/core/modules/layout_builder/layout_builder.routing.yml @@ -99,7 +99,7 @@ layout_builder.remove_block: layout_builder_tempstore: TRUE layout_builder.move_block: - path: '/layout_builder/move/block/{section_storage_type}/{section_storage}/{delta_from}/{delta_to}/{region_from}/{region_to}/{block_uuid}/{preceding_block_uuid}' + path: '/layout_builder/move/block/{section_storage_type}/{section_storage}/{delta_from}/{delta_to}/{region_to}/{block_uuid}/{preceding_block_uuid}' defaults: _controller: '\Drupal\layout_builder\Controller\MoveBlockController::build' delta_from: null diff --git a/core/modules/layout_builder/src/Controller/LayoutBuilderController.php b/core/modules/layout_builder/src/Controller/LayoutBuilderController.php index 3f3b95e49b2155db92a5bc7072594f3c2a2ddfd0..5ccddfac38aad248a57225142861d9bd81c39c77 100644 --- a/core/modules/layout_builder/src/Controller/LayoutBuilderController.php +++ b/core/modules/layout_builder/src/Controller/LayoutBuilderController.php @@ -215,7 +215,7 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s ]; $build[$region]['layout_builder_add_block']['#type'] = 'container'; $build[$region]['layout_builder_add_block']['#attributes'] = ['class' => ['add-block']]; - $build[$region]['layout_builder_add_block']['#weight'] = -1000; + $build[$region]['layout_builder_add_block']['#weight'] = 1000; $build[$region]['#attributes']['data-region'] = $region; $build[$region]['#attributes']['class'][] = 'layout-builder--layout__region'; } diff --git a/core/modules/layout_builder/src/Controller/MoveBlockController.php b/core/modules/layout_builder/src/Controller/MoveBlockController.php index 7411aa0bbe3ba6ad4595699230eb7f2488a3bba5..cb8e71f4b7e71c076a69f5b6a30530b99afa2e5a 100644 --- a/core/modules/layout_builder/src/Controller/MoveBlockController.php +++ b/core/modules/layout_builder/src/Controller/MoveBlockController.php @@ -56,8 +56,6 @@ public static function create(ContainerInterface $container) { * The delta of the original section. * @param int $delta_to * The delta of the destination section. - * @param string $region_from - * The original region for this block. * @param string $region_to * The new region for this block. * @param string $block_uuid @@ -68,7 +66,7 @@ public static function create(ContainerInterface $container) { * @return \Drupal\Core\Ajax\AjaxResponse * An AJAX response. */ - public function build(SectionStorageInterface $section_storage, $delta_from, $delta_to, $region_from, $region_to, $block_uuid, $preceding_block_uuid = NULL) { + public function build(SectionStorageInterface $section_storage, $delta_from, $delta_to, $region_to, $block_uuid, $preceding_block_uuid = NULL) { $section = $section_storage->getSection($delta_from); $component = $section->getComponent($block_uuid); @@ -87,7 +85,7 @@ public function build(SectionStorageInterface $section_storage, $delta_from, $de $section->insertAfterComponent($preceding_block_uuid, $component); } else { - $section->appendComponent($component); + $section->insertComponent(0, $component); } $this->layoutTempstoreRepository->set($section_storage);