diff --git a/composer.json b/composer.json index 03c87a7c..fbb12281 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "psr/log": "^1.0 || ^2.0 || ^3.0", "sonata-project/admin-bundle": "^3.90 || ^4.0", "sonata-project/doctrine-extensions": "^1.5.1", + "symfony/asset": "^4.4 || ^5.3", "symfony/config": "^4.4 || ^5.3", "symfony/dependency-injection": "^4.4 || ^5.3", "symfony/event-dispatcher": "^4.4 || ^5.3", @@ -57,7 +58,6 @@ "ergebnis/composer-normalize": "^2.0.1", "knplabs/knp-menu": "^2.3 || ^3.0", "sonata-project/doctrine-orm-admin-bundle": "^3.13 || ^4.0", - "symfony/asset": "^4.4 || ^5.3", "symfony/browser-kit": "^4.4 || ^5.3", "symfony/doctrine-bridge": "^4.4 || ^5.3" }, diff --git a/src/Avatar/StaticAvatarResolver.php b/src/Avatar/StaticAvatarResolver.php index d3d47129..c04b417d 100644 --- a/src/Avatar/StaticAvatarResolver.php +++ b/src/Avatar/StaticAvatarResolver.php @@ -11,19 +11,26 @@ namespace Nucleos\UserAdminBundle\Avatar; +use Symfony\Component\Asset\Packages; use Symfony\Component\Security\Core\User\UserInterface; final class StaticAvatarResolver implements AvatarResolver { private string $defaultAvatar; + private ?Packages $packages; - public function __construct(string $defaultAvatar) + public function __construct(string $defaultAvatar, ?Packages $packages = null) { + $this->packages = $packages; $this->defaultAvatar = $defaultAvatar; } public function avatarUrl(?UserInterface $user): string { - return $this->defaultAvatar; + if (null === $this->packages) { + return $this->defaultAvatar; + } + + return $this->packages->getUrl($this->defaultAvatar); } } diff --git a/src/Resources/config/avatar.php b/src/Resources/config/avatar.php index 440c8b37..d693d054 100644 --- a/src/Resources/config/avatar.php +++ b/src/Resources/config/avatar.php @@ -15,6 +15,7 @@ use Nucleos\UserAdminBundle\Avatar\StaticAvatarResolver; use Nucleos\UserAdminBundle\Twig\AvatarExtension; use Nucleos\UserAdminBundle\Twig\AvatarRuntime; +use Symfony\Component\Asset\Packages; return static function (ContainerConfigurator $container): void { $container->services() @@ -33,6 +34,7 @@ ->set(StaticAvatarResolver::class) ->args([ '%nucleos_user_admin.default_avatar%', + ref(Packages::class), ]) ->alias(AvatarResolver::class, StaticAvatarResolver::class)