2017-11-17 132 views
0

我发现如何打开使用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'])); 

但是现在我如何编程关闭此窗口?或者更简单地说,我想在模式底部提供一个“取消”按钮?

+0

所有jQuery UI的,https://api.drupal.org/api/drupal/core%21lib%21Drupal% 21Core%21Ajax%21OpenModalDialogCommand.php/class/OpenModalDialogCommand/8.2.x你可以在 – vishwa

回答

0

不知道这是否是最好的方法,但是如果你调用一个调用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' 

,然后控制器:

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