Update LB provided forms to fully support CreateDialog and DrupalAutoButtons within ui-dialog by implementing $form['actions']['#type'] = 'actions'

Created on 19 June 2024, 5 months ago
Updated 17 July 2024, 4 months ago

Problem/Motivation

When attempting to move core-provided form actions into the reserved button area that jQuery UI Dialog implements by setting drupalAutoButtons = TRUE within data-dialog-options, the expected behavior does not occur. Instead, only confirm forms (like delete block/section forms) move the buttons when in a dialog. This is because ConfirmFormBase seems to be the only base class that implements $form['actions']['#type'] = 'actions';. This theme wrapper type needs to be implemented in all AJAX forms that could be rendered in a modal/ui-dialog so that Drupal.behaviors.dialog::prepareDialogButtons can find the form actions based on the expected selectors (.form-actions input[type=submit], .form-actions a.button, .form-actions a.action-link).

Steps to Reproduce

  1. Create: Utilize hook_form_FORM_ID_alter() for ConfigureBlockFormBase (used in following examples) or any other Layout Builder provided form that extends FormBase.
  2. Create: Utilize hook_link_alter() for the link that corresponds to the form from the previous step:
    • Utilize hook_contextual_links_alter().
    • Implement $links['layout_builder_block_update']['localized_options']['attributes']['data-dialog-type'] = 'dialog';.
    • Update $links['layout_builder_block_update']['localized_options']['attributes']['data-dialog-options'] = Json::encode(['modal' => TRUE,]);.
    • Unset previous value(s) provided by core for off-canvas-settings: unset($links['layout_builder_block_update']['localized_options']['attributes']['data-dialog-renderer']);.
    • Further update ['data-dialog-options'] to move buttons/actions within ui-dialog: $variables['options']['attributes']['data-dialog-options'] = Json::encode(['drupalAutoButtons' => TRUE, 'buttons' => ['ok' => [],],]); (random "ok" button that does nothing, but helps in debugging).
  3. After flushing caches, note that the link now opens the targeted form in a dialog that utilizes jQuery UI Dialog, but the form actions have not been moved to the expected button area and are still rendered in the modal body.

Proposed Resolution

Update Layout Builder provided forms that extend FormBase to utilize the actions theme wrapper: $form['actions']['#type'] = 'actions';.

Remaining Tasks

  • Review the proposed changes.
  • Test the patch across various forms and scenarios.
  • Update documentation if necessary.

User Interface Changes

None

API Changes

None expected

Data Model Changes

None

Release Notes Snippet

TBD

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
Layout builderΒ  β†’

Last updated about 2 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States BLadwin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024