/** * 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))); }