gpt4 book ai didi

drupal-8 - 如何关闭模态窗口?

转载 作者:行者123 更新时间:2023-12-02 08:10:42 25 4
gpt4 key购买 nike

我找到了一些关于如何使用 Drupal 8 打开模态窗口的教程,并不难:

// Add an AJAX command to open a modal dialog with the form as the content.
$response->addCommand(new OpenModalDialogCommand('Load Window', $modal_form, ['width' => '800']));

但是现在如何以编程方式关闭此窗口?或者更简单地说,我希望在模态框底部有一个“取消”按钮?

最佳答案

不确定这是否是最好的方法,但如果您对调用 CloseModalDialogCommand() 的方法进行 ajax 调用,模态将关闭。

路线:

#Close the modal form
product.closeProductModal:
path: '/close-modal-form'
defaults:
_controller: '\Drupal\product\Controller\ModalController::closeModalForm'
_title: 'Close modal'
requirements:
_permission: 'access content'
_role: 'administrator'

然后是 Controller :

Use Drupal\Core\Ajax\CloseModalDialogCommand;
class ModalController extends ControllerBase {
public function closeModalForm(){
$command = new CloseModalDialogCommand();
$response = new AjaxResponse();
$response->addCommand($command);
return $response;
}
}

关于drupal-8 - 如何关闭模态窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47360131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com