本文整理汇总了PHP中AjaxResponse::addCommand方法的典型用法代码示例。如果您正苦于以下问题:PHP AjaxResponse::addCommand方法的具体用法?PHP AjaxResponse::addCommand怎么用?PHP AjaxResponse::addCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AjaxResponse
的用法示例。
在下文中一共展示了AjaxResponse::addCommand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ajaxOperation
/**
* Calls a method on a view and reloads the listing page.
*
* @param \Drupal\views\ViewStorageInterface $view
* The view being acted upon.
* @param string $op
* The operation to perform, e.g., 'enable' or 'disable'.
*
* @return \Drupal\Core\Ajax\AjaxResponse|\Symfony\Component\HttpFoundation\RedirectResponse
* Either returns a rebuilt listing page as an AJAX response, or redirects
* back to the listing page.
*/
public function ajaxOperation(ViewStorageInterface $view, $op, Request $request)
{
// Perform the operation.
$view->{$op}()->save();
// If the request is via AJAX, return the rendered list as JSON.
if ($request->request->get('js')) {
$list = $this->entityManager->getListController('view')->render();
$response = new AjaxResponse();
$response->addCommand(new ReplaceCommand('#views-entity-list', drupal_render($list)));
return $response;
}
// Otherwise, redirect back to the page.
// @todo Remove url() wrapper once http://drupal.org/node/1668866 is in.
return new RedirectResponse(url('admin/structure/views', array('absolute' => TRUE)));
}