OpenDialogCommand

Last updated on
27 January 2026

This documentation needs review. See "Help improve this page" in the sidebar.

Linked issue: #3546790: Implement OpenDialogCommand in htmx

Ajax API

Opens a dialog with provided content.

use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\OpenDialogCommand;
public function ajaxHandler(array $form, FormStateInterface $form_state) {
 $response = new AjaxResponse();
 $response->addCommand(
 new OpenDialogCommand(
 '#my-dialog', 
 $form['dialog_contents'], ['width' => 600]
 )
 );
 return $response;
}

HTMX

HTMX doesn’t define dialogs; you can implement them using native <dialog> and load the dialog body via HTMX, then open it after swap.

use Drupal\Core\Htmx\Htmx;
(new Htmx())
 ->get($dialogUrl)
 ->target('#my-dialog-content')
 ->swap('innerHTML')
 ->on('::afterSwap', 'document.getElementById("my-dialog")?.show()')
 ->applyTo($build['open_dialog_link_or_button']);

Documentation links

Help improve this page

Page status: Needs review

You can: