src/Controller/Admin/SortableController.php line 7

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use Sonata\AdminBundle\Controller\CRUDController;
  4. class SortableController extends CRUDController
  5. {
  6.     /**
  7.      * @param $position
  8.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  9.      */
  10.     public function moveAction($position)
  11.     {
  12.         $request $this->getRequest();
  13.         $id $request->get($this->admin->getIdParameter());
  14.         $existingObject $this->admin->getObject($id);
  15.         if (!$existingObject) {
  16.             throw $this->createNotFoundException(sprintf('unable to find the object with id: %s'$id));
  17.         }
  18.         $this->admin->checkAccess('edit'$existingObject);
  19.         if (method_exists($existingObject'setPosition')) {
  20.             $existingObject->setPosition($position);
  21.             $this->admin->update($existingObject);
  22.         }
  23.         return $this->renderJson(array(
  24.             'result' => 'ok',
  25.             'objectId' => $this->admin->getNormalizedIdentifier($existingObject)
  26.         ));
  27.     }
  28. }