diff --git a/core/modules/layout_builder/css/layout-builder.css b/core/modules/layout_builder/css/layout-builder.css index 0691f09..45daa82 100644 --- a/core/modules/layout_builder/css/layout-builder.css +++ b/core/modules/layout_builder/css/layout-builder.css @@ -40,20 +40,20 @@ background-image: url(../../../misc/icons/787878/ex.svg); } -#drupal-off-canvas details.layout-selection { +#drupal-off-canvas details.layout-selection { background-color: transparent; } -#drupal-off-canvas details.layout-selection summary { +#drupal-off-canvas details.layout-selection summary { margin-bottom: 1em; } -#drupal-off-canvas details.layout-selection li { +#drupal-off-canvas details.layout-selection li { display: block; padding-bottom: 1em; } -#drupal-off-canvas details.layout-selection li a { +#drupal-off-canvas details.layout-selection li a { display: block; padding-top: 0.55em; } diff --git a/core/modules/layout_builder/js/layout-builder.es6.js b/core/modules/layout_builder/js/layout-builder.es6.js index 56a921c..74a5cbb 100644 --- a/core/modules/layout_builder/js/layout-builder.es6.js +++ b/core/modules/layout_builder/js/layout-builder.es6.js @@ -1,18 +1,27 @@ -(function ($, Drupal) { - - Drupal.behaviors.layoutBuilder = { - - attach: function (context) { +(($, { ajax, behaviors }) => { + behaviors.layoutBuilder = { + attach(context) { $(context).find('.layout__region').sortable({ items: '> .draggable', connectWith: '.layout__region', - update: function (event, ui) { - let data = { + + /** + * Updates the layout with the new position of the block. + * + * @param {jQuery.Event} event + * The jQuery Event object. + * @param {Object} ui + * An object containing information about the item being sorted. + */ + update(event, ui) { + const data = { region_to: $(this).data('region'), block_uuid: ui.item.data('layout-block-uuid'), delta_to: ui.item.closest('[data-layout-delta]').data('layout-delta'), - preceding_block_uuid: ui.item.prev('[data-layout-block-uuid]').data('layout-block-uuid') + preceding_block_uuid: ui.item.prev('[data-layout-block-uuid]').data('layout-block-uuid'), }; + + // @todo What does this condition guard against? if (this === ui.item.parent()[0]) { if (ui.sender) { data.region_from = ui.sender.data('region'); @@ -23,18 +32,13 @@ data.delta_from = data.delta_to; } - let url = ui.item.closest('[data-layout-update-url]').data('layout-update-url'); - - let ajax = Drupal.ajax({ - url: url, - submit: data - }); - ajax.execute(); + ajax({ + url: ui.item.closest('[data-layout-update-url]').data('layout-update-url'), + submit: data, + }).execute(); } - } + }, }); - } - + }, }; - })(jQuery, Drupal); diff --git a/core/modules/layout_builder/js/layout-builder.js b/core/modules/layout_builder/js/layout-builder.js index eca948d..c56b992 100644 --- a/core/modules/layout_builder/js/layout-builder.js +++ b/core/modules/layout_builder/js/layout-builder.js @@ -5,14 +5,16 @@ * @preserve **/ -(function ($, Drupal) { - - Drupal.behaviors.layoutBuilder = { +(function ($, _ref) { + var ajax = _ref.ajax, + behaviors = _ref.behaviors; + behaviors.layoutBuilder = { attach: function attach(context) { $(context).find('.layout__region').sortable({ items: '> .draggable', connectWith: '.layout__region', + update: function update(event, ui) { var data = { region_to: $(this).data('region'), @@ -20,6 +22,7 @@ delta_to: ui.item.closest('[data-layout-delta]').data('layout-delta'), preceding_block_uuid: ui.item.prev('[data-layout-block-uuid]').data('layout-block-uuid') }; + if (this === ui.item.parent()[0]) { if (ui.sender) { data.region_from = ui.sender.data('region'); @@ -29,17 +32,13 @@ data.delta_from = data.delta_to; } - var url = ui.item.closest('[data-layout-update-url]').data('layout-update-url'); - - var ajax = Drupal.ajax({ - url: url, + ajax({ + url: ui.item.closest('[data-layout-update-url]').data('layout-update-url'), submit: data - }); - ajax.execute(); + }).execute(); } } }); } - }; })(jQuery, Drupal); \ No newline at end of file diff --git a/core/modules/layout_builder/layout_builder.info.yml b/core/modules/layout_builder/layout_builder.info.yml index d7bedde..7947421 100644 --- a/core/modules/layout_builder/layout_builder.info.yml +++ b/core/modules/layout_builder/layout_builder.info.yml @@ -6,4 +6,5 @@ version: VERSION core: 8.x dependencies: - layout_discovery + # @todo Remove dependency once https://www.drupal.org/node/2784443 is in. - settings_tray diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index b9e30a3..eb37353 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -24,23 +24,6 @@ function layout_builder_help($route_name) { } /** - * Implements hook_contextual_links_view_alter(). - * - * Change Configure Blocks into off_canvas links. - */ -function layout_builder_contextual_links_view_alter(&$element, $items) { - // @todo Move this to system_contextual_links_view_alter(). - // If any items use the off_canvas render, add the corresponding library. - foreach ($items as $item) { - if (isset($item['localized_options']['attributes']['data-dialog-renderer']) && $item['localized_options']['attributes']['data-dialog-renderer'] === 'off_canvas') { - $element['#attached']['library'][] = 'settings_tray/drupal.off_canvas'; - // After finding one, stop. - break; - } - } -} - -/** * Implements hook_form_FORM_ID_alter() for \Drupal\field_ui\Form\EntityViewDisplayEditForm. */ function layout_builder_form_entity_view_display_edit_form_alter(&$form, FormStateInterface $form_state) { @@ -49,7 +32,7 @@ function layout_builder_form_entity_view_display_edit_form_alter(&$form, FormSta $entity_type = \Drupal::entityTypeManager()->getDefinition($display->getTargetEntityTypeId()); // Remove layout_builder__layout both visually and from the #fields handling. - // This prevents any interaction with this field. It is manipulated directly + // This prevents any interaction with this field. It is rendered directly // in layout_builder_entity_view_display_alter(). unset($form['fields']['layout_builder__layout']); unset($form['#fields'][array_search('layout_builder__layout', $form['#fields'])]); @@ -68,6 +51,7 @@ function layout_builder_form_entity_view_display_edit_form_alter(&$form, FormSta '#default_value' => $display->getThirdPartySetting('layout_builder', 'allow_custom', FALSE), ]; + // The submit handler should run before the entity is saved by the form. array_unshift($form['actions']['submit']['#submit'], 'layout_builder_form_entity_view_display_edit_submit'); } diff --git a/core/modules/layout_builder/layout_builder.services.yml b/core/modules/layout_builder/layout_builder.services.yml index dcb254d..defcfca 100644 --- a/core/modules/layout_builder/layout_builder.services.yml +++ b/core/modules/layout_builder/layout_builder.services.yml @@ -9,7 +9,7 @@ services: class: Drupal\layout_builder\Access\LayoutSectionAccessCheck arguments: ['@entity_type.manager'] tags: - - { name: access_check, applies_to: _has_layout_selection } + - { name: access_check, applies_to: _has_layout_section } layout_builder.routes: class: Drupal\layout_builder\Routing\LayoutBuilderRoutes arguments: ['@entity_type.manager'] diff --git a/core/modules/layout_builder/src/Form/ConfigureBlockForm.php b/core/modules/layout_builder/src/Form/ConfigureBlockForm.php index bb60337..fb5cf93 100644 --- a/core/modules/layout_builder/src/Form/ConfigureBlockForm.php +++ b/core/modules/layout_builder/src/Form/ConfigureBlockForm.php @@ -221,7 +221,6 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t ]; $form['#attached']['library'][] = 'core/drupal.dialog.ajax'; - $form['#attributes']['id'] = 'dialog-form'; return $form; } diff --git a/core/modules/layout_builder/src/Plugin/Field/FieldType/LayoutSectionItem.php b/core/modules/layout_builder/src/Plugin/Field/FieldType/LayoutSectionItem.php index 2ca2248..d870b95 100644 --- a/core/modules/layout_builder/src/Plugin/Field/FieldType/LayoutSectionItem.php +++ b/core/modules/layout_builder/src/Plugin/Field/FieldType/LayoutSectionItem.php @@ -33,7 +33,7 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel ->setLabel(new TranslatableMarkup('Layout')) ->setSetting('case_sensitive', FALSE) ->setRequired(TRUE); - $properties[static::mainPropertyName()] = MapDataDefinition::create('map') + $properties['section'] = MapDataDefinition::create('map') ->setLabel(new TranslatableMarkup('Layout Section')) ->setRequired(FALSE); @@ -58,7 +58,7 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) 'length' => '255', 'binary' => FALSE, ], - static::mainPropertyName() => [ + 'section' => [ 'type' => 'blob', 'size' => 'normal', 'serialize' => TRUE, @@ -74,7 +74,7 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) */ public static function generateSampleValue(FieldDefinitionInterface $field_definition) { $values['layout'] = 'layout_onecol'; - $values[static::mainPropertyName()] = []; + $values['section'] = []; return $values; } diff --git a/core/modules/layout_builder/src/Routing/LayoutBuilderRoutes.php b/core/modules/layout_builder/src/Routing/LayoutBuilderRoutes.php index 0566132..7a53f52 100644 --- a/core/modules/layout_builder/src/Routing/LayoutBuilderRoutes.php +++ b/core/modules/layout_builder/src/Routing/LayoutBuilderRoutes.php @@ -51,7 +51,7 @@ public function getRoutes() { ]) ->addRequirements([ $entity_type_id => '\d+', - '_has_layout_selection' => 'true', + '_has_layout_section' => 'true', ]) ->addOptions([ '_layout_builder' => TRUE, @@ -71,7 +71,7 @@ public function getRoutes() { ]) ->addRequirements([ $entity_type_id => '\d+', - '_has_layout_selection' => 'true', + '_has_layout_section' => 'true', ]) ->addOptions([ '_layout_builder' => TRUE, @@ -91,7 +91,7 @@ public function getRoutes() { ]) ->addRequirements([ $entity_type_id => '\d+', - '_has_layout_selection' => 'true', + '_has_layout_section' => 'true', ]) ->addOptions([ '_layout_builder' => TRUE,