diff --git a/core/lib/Drupal/Core/Ajax/CloseModalDialogCommand.php b/core/lib/Drupal/Core/Ajax/CloseModalDialogCommand.php index a9c3fe702e..afb48448de 100644 --- a/core/lib/Drupal/Core/Ajax/CloseModalDialogCommand.php +++ b/core/lib/Drupal/Core/Ajax/CloseModalDialogCommand.php @@ -14,9 +14,12 @@ class CloseModalDialogCommand extends CloseDialogCommand { * * @param bool $persist * (optional) Whether to persist the dialog in the DOM or not. + * @param null|string $selector + * (optional) Selector to scope the modal. Only modals of the same scope + * will be removed after opening a subsequent modal. */ - public function __construct($persist = FALSE) { - $this->selector = '#drupal-modal'; + public function __construct($persist = FALSE, $selector = NULL) { + $this->selector = $selector ?: '#drupal-modal'; $this->persist = $persist; } diff --git a/core/lib/Drupal/Core/Ajax/OpenModalDialogCommand.php b/core/lib/Drupal/Core/Ajax/OpenModalDialogCommand.php index a55b0eaf60..0aa684c5fb 100644 --- a/core/lib/Drupal/Core/Ajax/OpenModalDialogCommand.php +++ b/core/lib/Drupal/Core/Ajax/OpenModalDialogCommand.php @@ -29,10 +29,13 @@ class OpenModalDialogCommand extends OpenDialogCommand { * (optional) Custom settings that will be passed to the Drupal behaviors * on the content of the dialog. If left empty, the settings will be * populated automatically from the current request. + * @param null|string $selector + * (optional) Selector to scope the modal. Only modals of the same scope + * will be removed after opening a subsequent modal. */ - public function __construct($title, $content, array $dialog_options = [], $settings = NULL) { + public function __construct($title, $content, array $dialog_options = [], $settings = NULL, $selector = NULL) { $dialog_options['modal'] = TRUE; - parent::__construct('#drupal-modal', $title, $content, $dialog_options, $settings); + parent::__construct($selector ?: '#drupal-modal', $title, $content, $dialog_options, $settings); } } diff --git a/core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php b/core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php index d250d57329..8eb356ae58 100644 --- a/core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php +++ b/core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php @@ -33,7 +33,8 @@ public function renderResponse(array $main_content, Request $request, RouteMatch // otherwise get it from the routing information. $options = $request->request->get('dialogOptions', []); - $response->addCommand(new OpenModalDialogCommand($title, $content, $options)); + $modal_selector = $main_content['#modal_selector'] ?? NULL; + $response->addCommand(new OpenModalDialogCommand($title, $content, $options, NULL, $modal_selector)); return $response; }