X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fentityqueue%2Fsrc%2FController%2FEntityQueueUIController.php;fp=web%2Fmodules%2Fcontrib%2Fentityqueue%2Fsrc%2FController%2FEntityQueueUIController.php;h=58be72fd2c88657a6e966d0c6196afcfa80fda03;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/entityqueue/src/Controller/EntityQueueUIController.php b/web/modules/contrib/entityqueue/src/Controller/EntityQueueUIController.php new file mode 100644 index 000000000..58be72fd2 --- /dev/null +++ b/web/modules/contrib/entityqueue/src/Controller/EntityQueueUIController.php @@ -0,0 +1,76 @@ +entityTypeManager()->getListBuilder('entity_subqueue'); + $list_builder->setQueueId($entity_queue->id()); + + return $list_builder->render(); + } + + /** + * Returns a form to add a new subqeue. + * + * @param \Drupal\entityqueue\EntityQueueInterface $entity_queue + * The queue this subqueue will be added to. + * + * @return array + * The entity subqueue add form. + */ + public function addForm(EntityQueueInterface $entity_queue) { + $subqueue = $this->entityTypeManager()->getStorage('entity_subqueue')->create(['queue' => $entity_queue->id()]); + return $this->entityFormBuilder()->getForm($subqueue); + } + + /** + * Calls a method on an entity queue and reloads the listing page. + * + * @param \Drupal\entityqueue\EntityQueueInterface $entity_queue + * The view being acted upon. + * @param string $op + * The operation to perform, e.g., 'enable' or 'disable'. + * @param \Symfony\Component\HttpFoundation\Request $request + * The current request. + * + * @return \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. + */ + 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'); + } + +}