<?php
namespace App\Controller\Admin;
use Sonata\AdminBundle\Controller\CRUDController;
class SortableController extends CRUDController
{
/**
* @param $position
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function moveAction($position)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
$existingObject = $this->admin->getObject($id);
if (!$existingObject) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$this->admin->checkAccess('edit', $existingObject);
if (method_exists($existingObject, 'setPosition')) {
$existingObject->setPosition($position);
$this->admin->update($existingObject);
}
return $this->renderJson(array(
'result' => 'ok',
'objectId' => $this->admin->getNormalizedIdentifier($existingObject)
));
}
}