From 48aefb1862f527e835cfd5a0d80d9ac2420db73a Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 30 Oct 2019 14:00:48 +0100 Subject: [PATCH] fix avatar path for subdirectory installations (#1201) --- config/packages/assets.yaml | 3 +++ config/packages/framework.yaml | 3 --- src/Twig/AvatarExtension.php | 2 +- src/Utils/AvatarService.php | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config/packages/assets.yaml b/config/packages/assets.yaml index 051d36dc..98263b8a 100644 --- a/config/packages/assets.yaml +++ b/config/packages/assets.yaml @@ -1,3 +1,6 @@ framework: assets: json_manifest_path: '%kernel.project_dir%/public/build/manifest.json' + packages: + avatars: + base_path: 'avatars' diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index 0d00791c..29c33e2b 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -29,6 +29,3 @@ framework: #validation: # possible values: 'loose', 'strict', 'html5' #email_validation_mode: 'html5' - - assets: - json_manifest_path: '%kernel.project_dir%/public/build/manifest.json' diff --git a/src/Twig/AvatarExtension.php b/src/Twig/AvatarExtension.php index 086f7cbf..b812b02a 100644 --- a/src/Twig/AvatarExtension.php +++ b/src/Twig/AvatarExtension.php @@ -54,6 +54,6 @@ class AvatarExtension extends AbstractExtension return $this->packages->getUrl($default); } - return $this->packages->getUrl($url); + return $this->packages->getUrl($url, 'avatars'); } } diff --git a/src/Utils/AvatarService.php b/src/Utils/AvatarService.php index cff35f07..15beb90c 100644 --- a/src/Utils/AvatarService.php +++ b/src/Utils/AvatarService.php @@ -110,14 +110,14 @@ class AvatarService private function getAvatarUrl(User $profile): string { - return '/avatars/' . md5($profile->getId() . '_' . $profile->getDisplayName()) . '.png'; + return md5($profile->getId() . '_' . $profile->getDisplayName()) . '.png'; } private function getImagePath(User $profile): string { - $avatarPath = realpath($this->projectDirectory . '/public/'); + $avatarPath = realpath($this->projectDirectory . '/public/avatars/'); - return $avatarPath . $this->getAvatarUrl($profile); + return $avatarPath . '/' . $this->getAvatarUrl($profile); } public function generateAvatar(User $profile, bool $regenerate = false): bool