APYBreadcrumbTrailBundle icon indicating copy to clipboard operation
APYBreadcrumbTrailBundle copied to clipboard

Working without sensio extra framework

Open phillamarmotte opened this issue 1 year ago • 3 comments

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

phillamarmotte avatar Jun 30 '23 09:06 phillamarmotte

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.

rvanlaak avatar Jun 30 '23 15:06 rvanlaak

OK. thank you for the answer.

phillamarmotte avatar Jul 03 '23 08:07 phillamarmotte

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

phillamarmotte avatar Jul 05 '23 07:07 phillamarmotte