3 namespace Drupal\entityqueue\Controller;
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\entityqueue\EntityQueueInterface;
7 use Symfony\Component\HttpFoundation\Request;
8 use Drupal\Core\Ajax\AjaxResponse;
9 use Drupal\Core\Ajax\ReplaceCommand;
12 * Returns responses for Views UI routes.
14 class EntityQueueUIController extends ControllerBase {
17 * Provides a list of all the subqueues of an entity queue.
19 * @param \Drupal\entityqueue\EntityQueueInterface $entity_queue
25 public function subqueueList(EntityQueueInterface $entity_queue) {
26 $list_builder = $this->entityTypeManager()->getListBuilder('entity_subqueue');
27 $list_builder->setQueueId($entity_queue->id());
29 return $list_builder->render();
33 * Returns a form to add a new subqeue.
35 * @param \Drupal\entityqueue\EntityQueueInterface $entity_queue
36 * The queue this subqueue will be added to.
39 * The entity subqueue add form.
41 public function addForm(EntityQueueInterface $entity_queue) {
42 $subqueue = $this->entityTypeManager()->getStorage('entity_subqueue')->create(['queue' => $entity_queue->id()]);
43 return $this->entityFormBuilder()->getForm($subqueue);
47 * Calls a method on an entity queue and reloads the listing page.
49 * @param \Drupal\entityqueue\EntityQueueInterface $entity_queue
50 * The view being acted upon.
52 * The operation to perform, e.g., 'enable' or 'disable'.
53 * @param \Symfony\Component\HttpFoundation\Request $request
54 * The current request.
56 * @return \Drupal\Core\Ajax\AjaxResponse|\Symfony\Component\HttpFoundation\RedirectResponse
57 * Either returns a rebuilt listing page as an AJAX response, or redirects
58 * back to the listing page.
60 public function ajaxOperation(EntityQueueInterface $entity_queue, $op, Request $request) {
61 // Perform the operation.
62 $entity_queue->$op()->save();
64 // If the request is via AJAX, return the rendered list as JSON.
65 if ($request->request->get('js')) {
66 $list = $this->entityTypeManager()->getListBuilder('entity_queue')->render();
67 $response = new AjaxResponse();
68 $response->addCommand(new ReplaceCommand('#entity-queue-list', $list));
72 // Otherwise, redirect back to the page.
73 return $this->redirect('entity.entity_queue.collection');