Page callback: Calls a method on a view and reloads the listing page.
Drupal\views\ViewExectuable $view: The config entity being acted upon.
string $op: The operation to perform, e.g., 'enable' or 'disable'.
mixed Either returns the listing page as JSON, or calls drupal_goto() to redirect back to the listing page.
function views_ui_ajax_callback(ViewExecutable $view, $op) {
// Perform the operation.
$view->storage
->{$op}();
// If the request is via AJAX, return the rendered list as JSON.
if (drupal_container()
->get('request')->request
->get('js')) {
$list = entity_list_controller('view')
->render();
$commands = array(
ajax_command_replace('#views-entity-list', drupal_render($list)),
);
return new JsonResponse(ajax_render($commands));
}
else {
$entity_info = entity_get_info('view');
drupal_goto('admin/structure/views');
}
}