Ajaxify links within modal

Created on 13 June 2025, 15 days ago

I want to open the content add page in a modal, choose a bundle, and then see the form in the modal.

This would be useful for the add content button on the admin content listing. I tested by modifying the render array and populating links with the use-ajax class, drupal-dialog-type="modal", and setting the destination url to the current page. The url is tricky since we don't see the original path in the ajax request. This could be set with javascript when the modal opens.

I'm working on resolving some issues with Views Add Button.

Currently, Admin Dialogs works well with the module, with the exception of being able to refresh the view after creating content. https://www.drupal.org/project/views_add_button/issues/3529307 ✨ Open in modal and reload view with ajax Active

I added the ability to create a Views Add Button for the content add page. https://www.drupal.org/project/views_add_button/issues/3529943 ✨ Link to entity add page without bundle Active

With the destination set, the view just reloads, which is not too bad. To get it to refresh with ajax when the form is submitted, I think some javascript needs to be added that prevents submission, submits with js, closes the dialog, and triggers a views ajax command.

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

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

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

Comments & Activities

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

    I figured out how to do this and added a patch for Views Add Button.

    The trick was to call Drupal.attachBehaviors(element) after adding the dialog attributes to the links.

    I will follow up on this work in https://www.drupal.org/project/views_add_button/issues/3529307 ✨ Open in modal and reload view with ajax Active .

    Currently, I'm able to set up an Add content button in the admin content view that can load the content add page, select a type, fill out the form, and refresh the view.

    There is already an Add content action button on that page, which can be set up to use a dialog with Admin Dialogs. This script would be useful in the same way, to ajaxify the links on the page and allow the form to load in the modal.

    https://git.drupalcode.org/project/views_add_button/-/blob/978b1d92cb8d1...

Production build 0.71.5 2024