diff --git a/src/Controller/CRUDController.php b/src/Controller/CRUDController.php index 8dd1dbffac..16224fd5ee 100644 --- a/src/Controller/CRUDController.php +++ b/src/Controller/CRUDController.php @@ -950,10 +950,8 @@ final public function configureAdmin(Request $request): void * * @param string $view The view name * @param array $parameters An array of parameters to pass to the view - * - * @return Response A Response instance */ - protected function renderWithExtraParams(string $view, array $parameters = [], ?Response $response = null): Response + final protected function renderWithExtraParams(string $view, array $parameters = [], ?Response $response = null): Response { return $this->render($view, $this->addRenderExtraParams($parameters), $response); } @@ -972,14 +970,10 @@ protected function addRenderExtraParams(array $parameters = []): array } /** - * Render JSON. - * * @param mixed $data * @param mixed[] $headers - * - * @return JsonResponse with json encoded data */ - protected function renderJson($data, int $status = Response::HTTP_OK, array $headers = []): JsonResponse + final protected function renderJson($data, int $status = Response::HTTP_OK, array $headers = []): JsonResponse { return new JsonResponse($data, $status, $headers); } @@ -989,7 +983,7 @@ protected function renderJson($data, int $status = Response::HTTP_OK, array $hea * * @return bool True if the request is an XMLHttpRequest, false otherwise */ - protected function isXmlHttpRequest(Request $request): bool + final protected function isXmlHttpRequest(Request $request): bool { return $request->isXmlHttpRequest() || $request->get('_xml_http_request'); } @@ -1032,17 +1026,17 @@ protected function getBaseTemplate(): string /** * @throws \Exception */ - protected function handleModelManagerException(\Exception $e): void + protected function handleModelManagerException(\Exception $exception): void { if ($this->getParameter('kernel.debug')) { - throw $e; + throw $exception; } - $context = ['exception' => $e]; - if (null !== $e->getPrevious()) { - $context['previous_exception_message'] = $e->getPrevious()->getMessage(); + $context = ['exception' => $exception]; + if (null !== $exception->getPrevious()) { + $context['previous_exception_message'] = $exception->getPrevious()->getMessage(); } - $this->getLogger()->error($e->getMessage(), $context); + $this->getLogger()->error($exception->getMessage(), $context); } /** @@ -1111,7 +1105,7 @@ final protected function redirectToList(): RedirectResponse /** * Returns true if the preview is requested to be shown. */ - protected function isPreviewRequested(Request $request): bool + final protected function isPreviewRequested(Request $request): bool { return null !== $request->get('btn_preview'); } @@ -1119,7 +1113,7 @@ protected function isPreviewRequested(Request $request): bool /** * Returns true if the preview has been approved. */ - protected function isPreviewApproved(Request $request): bool + final protected function isPreviewApproved(Request $request): bool { return null !== $request->get('btn_preview_approve'); } @@ -1130,7 +1124,7 @@ protected function isPreviewApproved(Request $request): bool * That means either a preview is requested or the preview has already been shown * and it got approved/declined. */ - protected function isInPreviewMode(Request $request): bool + final protected function isInPreviewMode(Request $request): bool { return $this->admin->supportsPreviewMode() && ($this->isPreviewRequested($request) @@ -1141,7 +1135,7 @@ protected function isInPreviewMode(Request $request): bool /** * Returns true if the preview has been declined. */ - protected function isPreviewDeclined(Request $request): bool + final protected function isPreviewDeclined(Request $request): bool { return null !== $request->get('btn_preview_decline'); } @@ -1202,7 +1196,7 @@ protected function getAclRoles(): \Traversable * * @throws HttpException */ - protected function validateCsrfToken(Request $request, string $intention): void + final protected function validateCsrfToken(Request $request, string $intention): void { if (!$this->has('security.csrf.token_manager')) { return; @@ -1220,15 +1214,15 @@ protected function validateCsrfToken(Request $request, string $intention): void /** * Escape string for html output. */ - protected function escapeHtml(string $s): string + final protected function escapeHtml(string $s): string { - return htmlspecialchars($s, \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8'); + return htmlspecialchars($s, \ENT_QUOTES | \ENT_SUBSTITUTE); } /** * Get CSRF token. */ - protected function getCsrfToken(string $intention): ?string + final protected function getCsrfToken(string $intention): ?string { if (!$this->has('security.csrf.token_manager')) { return null; @@ -1371,15 +1365,30 @@ final protected function assertObjectExists(Request $request, bool $strict = fal /** * @phpstan-return array{_tab?: string} */ - private function getSelectedTab(Request $request): array + final protected function getSelectedTab(Request $request): array { return array_filter(['_tab' => (string) $request->request->get('_tab')]); } + /** + * Sets the admin form theme to form view. Used for compatibility between Symfony versions. + * + * @param string[]|null $theme + */ + final protected function setFormTheme(FormView $formView, ?array $theme = null): void + { + $twig = $this->get('twig'); + \assert($twig instanceof Environment); + $formRenderer = $twig->getRuntime(FormRenderer::class); + \assert($formRenderer instanceof FormRenderer); + + $formRenderer->setTheme($formView, $theme); + } + /** * @phpstan-param T $object */ - private function checkParentChildAssociation(Request $request, object $object): void + final protected function checkParentChildAssociation(Request $request, object $object): void { if (!$this->admin->isChild()) { return; @@ -1441,19 +1450,4 @@ private function equalsOrContains($haystack, object $needle): bool return false; } - - /** - * Sets the admin form theme to form view. Used for compatibility between Symfony versions. - * - * @param string[]|null $theme - */ - private function setFormTheme(FormView $formView, ?array $theme = null): void - { - $twig = $this->get('twig'); - \assert($twig instanceof Environment); - $formRenderer = $twig->getRuntime(FormRenderer::class); - \assert($formRenderer instanceof FormRenderer); - - $formRenderer->setTheme($formView, $theme); - } }