2017-11-17 133 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; 
    } 
}