You are here

public function EntityQueueUIController::ajaxOperation in Entityqueue 8

Calls a method on an entity queue and reloads the listing page.

Parameters

\Drupal\entityqueue\EntityQueueInterface $entity_queue: 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 'EntityQueueUIController::ajaxOperation'
entityqueue.routing.yml in ./entityqueue.routing.yml
entityqueue.routing.yml

File

src/Controller/EntityQueueUIController.php, line 179

Class

EntityQueueUIController
Returns responses for Entityqueue UI routes.

Namespace

Drupal\entityqueue\Controller

Code

public function ajaxOperation(EntityQueueInterface $entity_queue, $op, Request $request) {

  // Perform the operation.
  $entity_queue
    ->{$op}()
    ->save();

  // If the request is via AJAX, return the rendered list as JSON.
  if ($request->request
    ->get('js')) {
    $list = $this
      ->entityTypeManager()
      ->getListBuilder('entity_queue')
      ->render();
    $response = new AjaxResponse();
    $response
      ->addCommand(new ReplaceCommand('#entity-queue-list', $list));
    return $response;
  }

  // Otherwise, redirect back to the page.
  return $this
    ->redirect('entity.entity_queue.collection');
}