public function ViewsUIController::ajaxOperation in Drupal 8
Same name and namespace in other branches
- 9 core/modules/views_ui/src/Controller/ViewsUIController.php \Drupal\views_ui\Controller\ViewsUIController::ajaxOperation()
- 10 core/modules/views_ui/src/Controller/ViewsUIController.php \Drupal\views_ui\Controller\ViewsUIController::ajaxOperation()
Calls a method on a view and reloads the listing page.
Parameters
\Drupal\views\ViewEntityInterface $view: The view being acted upon.
string $op: The operation to perform, e.g., 'enable' or 'disable'.
\Symfony\Component\HttpFoundation\Request $request: The current request.
Return value
\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.
1 string reference to 'ViewsUIController::ajaxOperation'
- views_ui.routing.yml in core/
modules/ views_ui/ views_ui.routing.yml - core/modules/views_ui/views_ui.routing.yml
File
- core/
modules/ views_ui/ src/ Controller/ ViewsUIController.php, line 159
Class
- ViewsUIController
- Returns responses for Views UI routes.
Namespace
Drupal\views_ui\ControllerCode
public function ajaxOperation(ViewEntityInterface $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
->entityTypeManager()
->getListBuilder('view')
->render();
$response = new AjaxResponse();
$response
->addCommand(new ReplaceCommand('#views-entity-list', $list));
return $response;
}
// Otherwise, redirect back to the page.
return $this
->redirect('entity.view.collection');
}