diff -u b/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php b/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php --- b/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php +++ b/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php @@ -8,11 +8,9 @@ use Drupal\Core\Ajax\RedirectCommand; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Block\BlockPluginInterface; -use Drupal\Core\Form\DialogFormTrait; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginWithFormsInterface; use Drupal\Core\Url; -use Drupal\outside_in\OffCanvasFormDialogTrait; /** * Provides form for block instance forms when used in the off-canvas dialog. @@ -120,26 +118,12 @@ /** * {@inheritdoc} */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - // \Drupal\block\BlockForm::submitForm() always redirects to block listing - // via \Drupal\Core\Form\FormStateInterface::setRedirect(). This method - // does not work with Ajax submit. - $form_state->disableRedirect(); - } - - /** - * {@inheritdoc} - */ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $form['actions']['submit']['#ajax'] = [ 'callback' => '::submitFormDialog', - 'event' => 'click', ]; - $form['#attached']['library'][] = 'core/drupal.dialog.ajax'; - $form['#attributes']['id'] = 'off-canvas-form'; return $form; } @@ -165,7 +149,7 @@ '#type' => 'status_messages', '#weight' => -1000, ]; - $command = new ReplaceCommand('#off-canvas-form', $form); + $command = new ReplaceCommand('[data-drupal-selector="' . $form['#attributes']['data-drupal-selector'] . '"]', $form); } else { if ($redirect_url = $this->getRedirectUrl()) { only in patch2: unchanged: --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -970,7 +970,7 @@ public function doBuildForm($form_id, &$element, FormStateInterface &$form_state // possible to rely on it in JavaScript. $element['#attributes']['data-drupal-selector'] = Html::getId($unprocessed_id); } - else { + elseif (!isset($element['#attributes']['data-drupal-selector'])) { // Provide a selector usable by JavaScript. As the ID is unique, its not // possible to rely on it in JavaScript. $element['#attributes']['data-drupal-selector'] = Html::getId($element['#id']);