APYBreadcrumbTrailBundle
APYBreadcrumbTrailBundle copied to clipboard
Working without sensio extra framework
Hi, I find an issue when we removed the deprecated sensioExtraFramework. The $request->attributes does not have the entity name ($varName) property. So it can't resolve the title like {user.username}.
I think i can decorate an event to fix add it but it seems a bad solution.
Best regards
FYI: The annotations you refer to were added to the symfony core a while back, but with this bundle some of the older Symfony versions that did not have the annotations in core are still supported. So, dropping that dependency on sensio-framework-extra-bundle would require bumping the requirements.
OK. thank you for the answer.
Hi, For information and if it can help anyone, I find a way to make it work without bumping the requirement. But it can work only in changing the event listening in the apiBreadcrumbTrailBundle service.xml
kernel.controller => kernel.controller_argument
edit : You can overide the event in the app service.yaml this way.
APY\BreadcrumbTrailBundle\EventListener\BreadcrumbListener:
tags:
- { name: kernel.event_listener, event: kernel.controller_arguments, method: onKernelController, priority: -1 }
and decorate the ValueResolverInterface in my code to simulate the old sensio-framework-extra-bundle behavior
<?php
namespace App\ArgumentResolver;
#[AsDecorator('doctrine.orm.entity_value_resolver')]
class SensioExtraFrameworkBehaviorEntityValueResolver implements ValueResolverInterface
{
public function __construct(
#[AutowireDecorated] private readonly EntityValueResolver $inner
) {
}
public function resolve(Request $request, ArgumentMetadata $argument): array
{
$object = $this->inner->resolve($request, $argument);
if (!empty($object)) {
$request->attributes->set($argument->getName(), $object[0]);
}
return $object;
}
}
this way the $request->attributes contain the resolved entity and everything works like before
Best regards