[MEDIA] Move avatar fetching and adding to ouput to media component

This commit is contained in:
Hugo Sales
2020-08-14 15:45:08 +00:00
committed by Hugo Sales
parent d4813b4ce9
commit 036b4480f3
2 changed files with 18 additions and 11 deletions

View File

@@ -19,12 +19,16 @@
namespace Component\Media;
use App\Core\DB\DB;
use App\Core\Event;
use App\Core\Log;
use App\Core\Module;
use App\Entity\File;
use App\Util\Common;
use App\Util\Exception\ClientException;
use App\Util\Nickname;
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\File as SymfonyFile;
@@ -87,4 +91,15 @@ class Media extends Module
{
$r->connect('avatar', '/{nickname<' . Nickname::DISPLAY_FMT . '>}/avatar/{size<full|big|medium|small>?full}', [Controller\Avatar::class, 'send']);
}
public function onEndTwigPopulateVars(array &$vars)
{
if (($user = Common::user()) !== null && ($avatar = DB::find('avatar', ['gsactor_id' => $user->getActor()->getId()])) != null) {
$vars['user_avatar'] = $avatar->getUrl();
} else {
$package = new Package(new EmptyVersionStrategy());
$vars['user_avatar'] = $package->getUrl('/assets/default-avatar.svg');
}
return Event::next;
}
}