diff --git a/CHANGELOG-4.0.md b/CHANGELOG-4.0.md index 734eb035cec..7ef8e131908 100644 --- a/CHANGELOG-4.0.md +++ b/CHANGELOG-4.0.md @@ -32,6 +32,8 @@ This file will get merged with CHANGELOG.md when releasing 4.0.0 - `AbstractAdmin::configureActionButtons` method signature has changed - Moved default buttons from `AbstractAdmin::configureActionButtons` to `AbstractAdmin::getActionButtons` - `AbstractAdmin::getBatchActions` is now final +- `CRUDController::handleXmlHttpRequestSuccessResponse` method is now protected +- `CRUDController::handleXmlHttpRequestErrorResponse` method is now protected ### Removed - Removed BC handler for deprecated `view` `_action` diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index d543d6996af..38604776d58 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -74,3 +74,8 @@ Method `SimplePager::getResults` is always returning an array ## LockInterface `LockInterface` extends from `ModelManagerInterface`. + +## CRUDController +The following methods changed their visiblity to protected: + * `handleXmlHttpRequestSuccessResponse` + * `handleXmlHttpRequestErrorResponse` diff --git a/src/Controller/CRUDController.php b/src/Controller/CRUDController.php index f591d2ca943..05e37ffb3e9 100644 --- a/src/Controller/CRUDController.php +++ b/src/Controller/CRUDController.php @@ -1381,6 +1381,41 @@ final protected function trans($id, array $parameters = [], $domain = null, $loc return $this->get('translator')->trans($id, $parameters, $domain, $locale); } + protected function handleXmlHttpRequestErrorResponse(Request $request, FormInterface $form): ?JsonResponse + { + if (!\in_array('application/json', $request->getAcceptableContentTypes(), true)) { + @trigger_error('In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`', E_USER_DEPRECATED); + + return null; + } + + $errors = []; + foreach ($form->getErrors(true) as $error) { + $errors[] = $error->getMessage(); + } + + return $this->renderJson([ + 'result' => 'error', + 'errors' => $errors, + ], Response::HTTP_BAD_REQUEST); + } + + /** + * @param object $object + */ + protected function handleXmlHttpRequestSuccessResponse(Request $request, $object): JsonResponse + { + if (!\in_array('application/json', $request->getAcceptableContentTypes(), true)) { + @trigger_error('In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`', E_USER_DEPRECATED); + } + + return $this->renderJson([ + 'result' => 'ok', + 'objectId' => $this->admin->getNormalizedIdentifier($object), + 'objectName' => $this->escapeHtml($this->admin->toString($object)), + ], Response::HTTP_OK); + } + private function getSelectedTab(Request $request): array { return array_filter(['_tab' => $request->request->get('_tab')]); @@ -1416,37 +1451,4 @@ private function setFormTheme(FormView $formView, ?array $theme = null): void $twig->getRuntime(FormRenderer::class)->setTheme($formView, $theme); } - - private function handleXmlHttpRequestErrorResponse(Request $request, FormInterface $form): JsonResponse - { - if (!\in_array('application/json', $request->getAcceptableContentTypes(), true)) { - return $this->renderJson([], Response::HTTP_NOT_ACCEPTABLE); - } - - $errors = []; - foreach ($form->getErrors(true) as $error) { - $errors[] = $error->getMessage(); - } - - return $this->renderJson([ - 'result' => 'error', - 'errors' => $errors, - ], Response::HTTP_BAD_REQUEST); - } - - /** - * @param object $object - */ - private function handleXmlHttpRequestSuccessResponse(Request $request, $object): JsonResponse - { - if (!\in_array('application/json', $request->getAcceptableContentTypes(), true)) { - return $this->renderJson([], Response::HTTP_NOT_ACCEPTABLE); - } - - return $this->renderJson([ - 'result' => 'ok', - 'objectId' => $this->admin->getNormalizedIdentifier($object), - 'objectName' => $this->escapeHtml($this->admin->toString($object)), - ], Response::HTTP_OK); - } }