Refactor service definitions in menu.yaml to use _defaults for autowiring and autoconfiguration, and update SectionMenuBuilder constructor with property promotion.

This commit is contained in:
2025-12-22 15:27:41 +01:00
parent a199f5983e
commit d714a61a6d
2 changed files with 28 additions and 40 deletions

View File

@@ -19,23 +19,10 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class SectionMenuBuilder implements LocalMenuBuilderInterface
{
/**
* @var AuthorizationCheckerInterface
*/
public $authorizationChecker;
/**
* @var TranslatorInterface
*/
public $translator;
public function __construct(
AuthorizationCheckerInterface $authorizationChecker,
TranslatorInterface $translator,
) {
$this->authorizationChecker = $authorizationChecker;
$this->translator = $translator;
}
private AuthorizationCheckerInterface $authorizationChecker,
private TranslatorInterface $translator,
) {}
public function buildMenu($menuId, MenuItem $menu, array $parameters): void
{
@@ -46,11 +33,11 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface
$menu->addChild(
$this->translator->trans('Tasks'),
[
'route' => 'chill_task_singletask_list', [
'routeParameters' => [
'hide_form' => false,
],
], ]
'route' => 'chill_task_singletask_list',
'routeParameters' => [
'hide_form' => false,
],
]
)
->setExtras([
'order' => 50,

View File

@@ -1,22 +1,23 @@
services:
Chill\TaskBundle\Menu\UserMenuBuilder:
arguments:
$tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'
$counter: '@Chill\TaskBundle\Templating\UI\CountNotificationTask'
$translator: '@Symfony\Contracts\Translation\TranslatorInterface'
$authorizationChecker: '@Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface'
tags:
- { name: "chill.menu_builder" }
_defaults:
autowire: true
autoconfigure: true
Chill\TaskBundle\Menu\MenuBuilder:
autowire: true
autoconfigure: true
tags:
- { name: "chill.menu_builder" }
Chill\TaskBundle\Menu\UserMenuBuilder:
arguments:
$tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'
$counter: '@Chill\TaskBundle\Templating\UI\CountNotificationTask'
$translator: '@Symfony\Contracts\Translation\TranslatorInterface'
$authorizationChecker: '@Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface'
tags:
- { name: "chill.menu_builder" }
Chill\TaskBundle\Menu\SectionMenuBuilder:
arguments:
$authorizationChecker: '@Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface'
$translator: '@Symfony\Contracts\Translation\TranslatorInterface'
tags:
- { name: "chill.menu_builder" }
Chill\TaskBundle\Menu\MenuBuilder:
autowire: true
autoconfigure: true
tags:
- { name: "chill.menu_builder" }
Chill\TaskBundle\Menu\SectionMenuBuilder:
tags:
- { name: "chill.menu_builder" }