public function ViewsUIController::ajaxOperation

Calls a method on a view and reloads the listing page.

Parameters

\Drupal\views\ViewStorageInterface $view: The view being acted upon.

string $op: The operation to perform, e.g., 'enable' or 'disable'.

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 drupal/core/modules/views_ui/views_ui.routing.yml
drupal/core/modules/views_ui/views_ui.routing.yml

File

drupal/core/modules/views_ui/lib/Drupal/views_ui/Controller/ViewsUIController.php, line 182
Contains \Drupal\views_ui\Controller\ViewsUIController.

Class

ViewsUIController
Returns responses for Views UI routes.

Namespace

Drupal\views_ui\Controller

Code

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,
  )));
}