You are here

public function ViewsUIController::ajaxOperation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 162
Contains \Drupal\views_ui\Controller\ViewsUIController.

Class

ViewsUIController
Returns responses for Views UI routes.

Namespace

Drupal\views_ui\Controller

Code

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
      ->entityManager()
      ->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');
}