Skip to content

Commit cea3081

Browse files
[FrameworkBundle] Add $block argument to AbstractController:render() and renderView()
1 parent f0959b4 commit cea3081

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

UPGRADE-6.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ FrameworkBundle
7878
---------------
7979

8080
* [BC break] Add native return type to `Translator` and to `Application::reset()`
81+
* Add `$block` argument to `AbstractController:render()` and `renderView()`
8182
* Deprecate the integration of Doctrine annotations, either uninstall the `doctrine/annotations` package or disable
8283
the integration by setting `framework.annotations` to `false`
8384

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
6.4
55
---
66

7+
* Add `$block` argument to `AbstractController:render()` and `renderView()`
78
* Add native return type to `Translator` and to `Application::reset()`
89
* Deprecate the integration of Doctrine annotations, either uninstall the `doctrine/annotations` package or disable the integration by setting `framework.annotations` to `false`
910
* Enable `json_decode_detailed_errors` context for Serializer by default if `kernel.debug` is true and the `seld/jsonlint` package is installed

src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,13 @@ protected function denyAccessUnlessGranted(mixed $attribute, mixed $subject = nu
226226
* Returns a rendered view.
227227
*
228228
* Forms found in parameters are auto-cast to form views.
229+
*
230+
* @param string|null $block
229231
*/
230-
protected function renderView(string $view, array $parameters = []): string
232+
protected function renderView(string $view, array $parameters = []/* , string $block = null */): string
231233
{
234+
$block = 2 < \func_num_args() ? func_get_arg(2) : null;
235+
232236
if (!$this->container->has('twig')) {
233237
throw new \LogicException('You cannot use the "renderView" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
234238
}
@@ -239,6 +243,10 @@ protected function renderView(string $view, array $parameters = []): string
239243
}
240244
}
241245

246+
if (null !== $block) {
247+
return $this->container->get('twig')->load($view)->renderBlock($block, $parameters);
248+
}
249+
242250
return $this->container->get('twig')->render($view, $parameters);
243251
}
244252

@@ -247,10 +255,13 @@ protected function renderView(string $view, array $parameters = []): string
247255
*
248256
* If an invalid form is found in the list of parameters, a 422 status code is returned.
249257
* Forms found in parameters are auto-cast to form views.
258+
*
259+
* @param string|null $block
250260
*/
251-
protected function render(string $view, array $parameters = [], Response $response = null): Response
261+
protected function render(string $view, array $parameters = [], Response $response = null/* , string $block = null */): Response
252262
{
253-
$content = $this->renderView($view, $parameters);
263+
$block = 2 < \func_num_args() ? func_get_arg(2) : null;
264+
$content = $this->renderView($view, $parameters, $block);
254265
$response ??= new Response();
255266

256267
if (200 === $response->getStatusCode()) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy