Commit 06343eff authored by webchick's avatar webchick
Browse files

Issue #2937159 by tim.plunkett, Kristen Pol, EclipseGc, drpal: Manipulating...

Issue #2937159 by tim.plunkett, Kristen Pol, EclipseGc, drpal: Manipulating placement of components in Layout Builder UI is inconsistent
parent e1a7b35c
......@@ -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'),
]
......
......@@ -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();
......
......@@ -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
......
......@@ -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';
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment