Skip to content

Commit

Permalink
Fix incompatibility to Symfony 6.4 renderBlock method (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored Aug 30, 2023
1 parent 859394b commit 766c235
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
13 changes: 8 additions & 5 deletions Controller/WebsiteArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function renderArticle(
if ($partial) {
$response = $this->createResponse($request);
$response->setContent(
$this->renderBlock(
$this->renderBlockView(
$viewTemplate,
'content',
$data
Expand Down Expand Up @@ -161,18 +161,21 @@ private function createResponse(Request $request): Response
return $response;
}

protected function renderBlock(string $template, string $block, array $attributes = []): string
/**
* @param array<string, mixed> $parameters
*/
protected function renderBlockView(string $view, string $block, array $parameters = []): string
{
$twig = $this->getTwig();

$attributes = $twig->mergeGlobals($attributes);
$template = $twig->load($template);
$parameters = $twig->mergeGlobals($parameters);
$template = $twig->load($view);

$level = \ob_get_level();
\ob_start();

try {
$rendered = $template->renderBlock($block, $attributes);
$rendered = $template->renderBlock($block, $parameters);
\ob_end_clean();

return $rendered;
Expand Down
9 changes: 8 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Upgrade

## 2.5.2

### Rename WebsiteArticleController::renderBlock to WebsiteArticleController::renderBlockView

In Symfony 6.4, an independent `renderBlock` method was introduced to its `AbstractController`.
This change poses issues for projects upgrading to Symfony 6.4, as the `renderBlock` method in Sulu is incompatible with Symfony's `renderBlock` method.
To address this issue, we have to rename the Sulu `renderBlock` method to `renderBlockView`.

## 2.3.0

### Changed constructor of ArticleObjectProvider
Expand Down Expand Up @@ -332,4 +340,3 @@ Reindex elastic search indexes:
bin/adminconsole sulu:article:index-rebuild ###LOCALE### --live
bin/adminconsole sulu:article:index-rebuild ###LOCALE###
```

5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,6 @@ parameters:
count: 1
path: Controller/WebsiteArticleController.php

-
message: "#^Method Sulu\\\\Bundle\\\\ArticleBundle\\\\Controller\\\\WebsiteArticleController\\:\\:renderBlock\\(\\) has parameter \\$attributes with no value type specified in iterable type array\\.$#"
count: 1
path: Controller/WebsiteArticleController.php

-
message: "#^Method Sulu\\\\Bundle\\\\ArticleBundle\\\\Controller\\\\WebsiteArticleController\\:\\:resolveArticle\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down

0 comments on commit 766c235

Please sign in to comment.