Open in modal and reload view with ajax

Created on 10 June 2025, 18 days ago

I'm currently using the Admin Dialogs module to open the entity create form in a modal.

It works well, but I have to manually add a class to all buttons and configure an admin dialog that targets it.

However, when the view has ajax enabled, it would be nice to close the modal and refresh the list, without reloading the window.

The proposal here is to add an option to open in a modal, and if ajax is enabled, use it to submit the form, close the modal, and reload the view.

✨ Feature request
Status

Active

Version

2.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

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

Merge Requests

Comments & Activities

  • Issue created by @mortona2k
  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    I added an issue for opening the entity add page to get the full list of bundles, with descriptions, which can be helpful for content entry: https://www.drupal.org/project/views_add_button/issues/3529943 ✨ Link to entity add page without bundle Active

    Still using Admin Dialogs for the modal. It's working, but the links redirect to the entity form instead of reloading in the modal.

    To fix, each link needs to have the use-ajax class, and drupal-dialog-type="modal".

    I tested this by modifying template_preprocess_admin_block_content(), where the links are generated. It works!

    To implement, we could add some js to add the attributes when the modal loads.

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    Here's a working proof of concept. It uses a form alter hook (currently only articles) to add an #ajax handler to the submit button to close the modal and refresh the view after submitting.

    But I have an error when ckeditor is in the form, so hide the body field before trying this.

    Here's the error:

    Uncaught TypeError: dialogSettings is undefined ckeditor5.js:681:23

    We can configure the attributes we need for the modal in the settings form so I wouldn't need Admin Dialogs, but the drupal.dialog.ajax library needs to be loaded. That could be set with a checkbox on the config form.

  • Merge request !14Add ajax callback to content form β†’ (Open) created by mortona2k
  • Pipeline finished with Success
    13 days ago
    Total: 150s
    #522104
  • Pipeline finished with Failed
    13 days ago
    Total: 150s
    #522124
  • Pipeline finished with Success
    13 days ago
    #522137
  • Pipeline finished with Success
    13 days ago
    #522523
  • Pipeline finished with Success
    13 days ago
    Total: 213s
    #522559
  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    Added dialog options.

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    Add instructions for dialog options.

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle
  • Pipeline finished with Success
    2 days ago
    Total: 221s
    #531540
Production build 0.71.5 2024