function ViewsUIController::ajaxOperation
Same name and namespace in other branches
- 11.x 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()
- 9 core/modules/views_ui/src/Controller/ViewsUIController.php \Drupal\views_ui\Controller\ViewsUIController::ajaxOperation()
- 8.9.x 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.
Attributes
#[Route(path: '/admin/structure/views/view/{view}/enable', name: 'entity.view.enable', defaults: [
'op' => 'enable',
], requirements: [
'_entity_access' => 'view.enable',
'_csrf_token' => 'TRUE',
])]
#[Route(path: '/admin/structure/views/view/{view}/disable', name: 'entity.view.disable', defaults: [
'op' => 'disable',
], requirements: [
'_entity_access' => 'view.disable',
'_csrf_token' => 'TRUE',
])]
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.
File
-
core/
modules/ views_ui/ src/ Controller/ ViewsUIController.php, line 163
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');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.