Node preview modal: use Drupal API

Created on 5 March 2025, 2 months ago

Problem/Motivation

In πŸ’¬ Additional modal support Active , to improve a proper support of Drupal dialog in Bootstrap, @tocab found out that the modal in the Node module which prevents leaving the node preview page is not using properly the Drupal dialog API.

So an override is not taken into account.

https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/node/...

Drupal.dialog($previewDialog, {
...
                click() {
                  $(this).dialog('close');
                },
              },
...

This is not using the dialog API, while other JS code in Core is implemented differently. Like in https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/edito...

const confirmationDialog = Drupal.dialog(`<div>${message}</div>`, {
...
        buttons: [
          {
            text: Drupal.t('Continue'),
            class: 'button button--primary',
            click() {
              changeTextEditor(field, newFormatID);
              confirmationDialog.close();
            },
          },
...
      });

      confirmationDialog.showModal();

using the "close" method on the instance of the dialog object.

Steps to reproduce

Proposed resolution

Update node.preview.js to use the same approach.

const confirmationDialog = Drupal.dialog($previewDialog, {
            title: Drupal.t('Leave preview?'),
            buttons: [
              {
                text: Drupal.t('Cancel'),
                click() {
                  confirmationDialog.close();
                },
              },
              {
                text: Drupal.t('Leave preview'),
                click() {
                  window.top.location.href = event.currentTarget.href;
                },
              },
            ],
          });
          confirmationDialog.showModal();

Remaining tasks

I will let @tocab create the MR as he is the one which found the issue and solution. I have only tested the solution.

- create a MR
- code review

User interface changes

None

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

node system

Created by

πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024