Problem/Motivation

Any layout builder page that has custom blocks loses the AJAX ability to remove content and do a page refresh.
In order words one can't remove a block from a layout builder page and close the off-canvas tray with AJAX

Steps to reproduce

To reproduce install the module and try to remove any block.
The block will action will be taken but ajax won't run. Hence the block stays, the off-canvas stays open and the page does not reload.

Proposed resolution

I propose narrowing its scope so it won't interfere with other Drupal functions.

API changes

I tracked the issue to this hook.

/**
 * Implements hook_form_alter().
 */
function entity_reference_actions_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  $is_ajax = FALSE;
  foreach (['drupal_ajax', 'drupal_modal', 'drupal_dialog'] as $wrapper) {
    if (strpos(\Drupal::request()->get(MainContentViewSubscriber::WRAPPER_FORMAT), $wrapper) !== FALSE) {
      $is_ajax = TRUE;
    }
  }

  if (!$is_ajax || !($form_state->getFormObject() instanceof ConfirmFormBase)) {
    return;
  }

  $form['actions']['submit']['#ajax']['callback'] = [
    EntityReferenceActionsHandler::class,
    'dialogAjaxSubmit',
  ];
  $form['actions']['cancel']['#attributes']['class'][] = 'dialog-cancel';
}
CommentFileSizeAuthor
#2 3191889.patch796 byteschr.fritsch

Comments

bernardm28 created an issue. See original summary.

chr.fritsch’s picture

Status: Active » Needs review
StatusFileSize
new796 bytes

Hi @bernardm28,

could you please test this patch. Thx

chr.fritsch’s picture

bernardm28’s picture

Hey, thanks for the patch. I haven't gone back to testing it yet. But the code looks good. Once I get it tested and I will let you know.

chr.fritsch’s picture

Any updates?

bernardm28’s picture

The patch works. Thanks for the contrib and sorry for the wait.
I try replicating the issue a few different ways but it seems like the issue its gone.
If there is a change you guys could do a demo video or blogpost about the module that be cool.

bernardm28’s picture

  • chr.fritsch committed 705c2a4 on 1.x
    Issue #3191889 by chr.fritsch, bernardm28: This module breaks the remove...
chr.fritsch’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.