|
@@ -14,6 +14,7 @@ namespace Sonata\AdminBundle\Controller;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
+use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\Form\Util\PropertyPath;
|
|
use Symfony\Component\Form\Util\PropertyPath;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Sonata\AdminBundle\Admin\Pool;
|
|
use Sonata\AdminBundle\Admin\Pool;
|
|
@@ -212,44 +213,32 @@ class HelperController
|
|
|
|
|
|
// alter should be done by using a post method
|
|
// alter should be done by using a post method
|
|
if ($request->getMethod() != 'POST') {
|
|
if ($request->getMethod() != 'POST') {
|
|
- return new Response(json_encode(array('status' => 'KO', 'message' => 'Expected a POST Request')), 200, array(
|
|
|
|
- 'Content-Type' => 'application/json'
|
|
|
|
- ));
|
|
|
|
|
|
+ return new JsonResponse(array('status' => 'KO', 'message' => 'Expected a POST Request'));
|
|
}
|
|
}
|
|
|
|
|
|
$object = $admin->getObject($objectId);
|
|
$object = $admin->getObject($objectId);
|
|
|
|
|
|
if (!$object) {
|
|
if (!$object) {
|
|
- return new Response(json_encode(array('status' => 'KO', 'message' => 'Object does not exist')), 200, array(
|
|
|
|
- 'Content-Type' => 'application/json'
|
|
|
|
- ));
|
|
|
|
|
|
+ return new JsonResponse(array('status' => 'KO', 'message' => 'Object does not exist'));
|
|
}
|
|
}
|
|
|
|
|
|
// check user permission
|
|
// check user permission
|
|
if (false === $admin->isGranted('EDIT', $object)) {
|
|
if (false === $admin->isGranted('EDIT', $object)) {
|
|
- return new Response(json_encode(array('status' => 'KO', 'message' => 'Invalid permissions')), 200, array(
|
|
|
|
- 'Content-Type' => 'application/json'
|
|
|
|
- ));
|
|
|
|
|
|
+ return new JsonResponse(array('status' => 'KO', 'message' => 'Invalid permissions'));
|
|
}
|
|
}
|
|
|
|
|
|
if ($context == 'list') {
|
|
if ($context == 'list') {
|
|
$fieldDescription = $admin->getListFieldDescription($field);
|
|
$fieldDescription = $admin->getListFieldDescription($field);
|
|
} else {
|
|
} else {
|
|
- return new Response(json_encode(array('status' => 'KO', 'message' => 'Invalid context')), 200, array(
|
|
|
|
- 'Content-Type' => 'application/json'
|
|
|
|
- ));
|
|
|
|
|
|
+ return new JsonResponse(array('status' => 'KO', 'message' => 'Invalid context'));
|
|
}
|
|
}
|
|
|
|
|
|
if (!$fieldDescription) {
|
|
if (!$fieldDescription) {
|
|
- return new Response(json_encode(array('status' => 'KO', 'message' => 'The field does not exist')), 200, array(
|
|
|
|
- 'Content-Type' => 'application/json'
|
|
|
|
- ));
|
|
|
|
|
|
+ return new JsonResponse(array('status' => 'KO', 'message' => 'The field does not exist'));
|
|
}
|
|
}
|
|
|
|
|
|
if (!$fieldDescription->getOption('editable')) {
|
|
if (!$fieldDescription->getOption('editable')) {
|
|
- return new Response(json_encode(array('status' => 'KO', 'message' => 'The field cannot be edit, editable option must be set to true')), 200, array(
|
|
|
|
- 'Content-Type' => 'application/json'
|
|
|
|
- ));
|
|
|
|
|
|
+ return new JsonResponse(array('status' => 'KO', 'message' => 'The field cannot be edit, editable option must be set to true'));
|
|
}
|
|
}
|
|
|
|
|
|
// TODO : call the validator component ...
|
|
// TODO : call the validator component ...
|
|
@@ -265,8 +254,6 @@ class HelperController
|
|
|
|
|
|
$content = $extension->renderListElement($object, $fieldDescription);
|
|
$content = $extension->renderListElement($object, $fieldDescription);
|
|
|
|
|
|
- return new Response(json_encode(array('status' => 'OK', 'content' => $content)), 200, array(
|
|
|
|
- 'Content-Type' => 'application/json'
|
|
|
|
- ));
|
|
|
|
|
|
+ return new JsonResponse(array('status' => 'OK', 'content' => $content));
|
|
}
|
|
}
|
|
}
|
|
}
|