mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-08 14:29:42 +00:00
Refactor MenuComposer
to improve type safety and simplify local menu builder integration
This commit is contained in:
@@ -18,7 +18,7 @@ use Twig\TwigFunction;
|
||||
/**
|
||||
* Add the filter 'chill_menu'.
|
||||
*/
|
||||
class MenuTwig extends AbstractExtension
|
||||
final class MenuTwig extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* the default parameters for chillMenu.
|
||||
@@ -43,22 +43,16 @@ class MenuTwig extends AbstractExtension
|
||||
*
|
||||
* @deprecated link: see https://redmine.champs-libres.coop/issues/179 for more informations
|
||||
*
|
||||
* @param string $menuId
|
||||
* @param mixed[] $params
|
||||
* @param array{layout?: string, activeRouteKey?: string|null, args?: array<array-key, mixed>} $params
|
||||
*/
|
||||
public function chillMenu(Environment $env, $menuId, array $params = [])
|
||||
public function chillMenu(Environment $env, string $menuId, array $params = []): string
|
||||
{
|
||||
$resolvedParams = array_merge($this->defaultParams, $params);
|
||||
|
||||
$layout = $resolvedParams['layout'];
|
||||
unset($resolvedParams['layout']);
|
||||
|
||||
if (false === $this->menuComposer->hasLocalMenuBuilder($menuId)) {
|
||||
$resolvedParams['routes'] = $this->menuComposer->getRoutesFor($menuId, $resolvedParams);
|
||||
|
||||
return $env->render($layout, $resolvedParams);
|
||||
}
|
||||
$resolvedParams['menus'] = $this->menuComposer->getMenuFor($menuId, $resolvedParams);
|
||||
$resolvedParams['menus'] = $resolvedParams['routes'] = $this->menuComposer->getMenuFor($menuId, $resolvedParams['args']);
|
||||
|
||||
return $env->render($layout, $resolvedParams);
|
||||
}
|
||||
|
Reference in New Issue
Block a user