Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Allow updating user avatar via
avatarUrl
attribute
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Maicol07\SSO\Listener; | ||
|
||
use Flarum\User\AvatarUploader; | ||
use Flarum\User\Event\Saving; | ||
use Illuminate\Support\Arr; | ||
use Intervention\Image\ImageManager; | ||
|
||
class UpdateUserAvatar | ||
{ | ||
final public function updateAvatarUrl(Saving $event): void | ||
{ | ||
$user = $event->user; | ||
$attributes = Arr::get($event->data, 'attributes', []); | ||
|
||
if (Arr::exists($attributes, 'avatarUrl')) { | ||
$image = (new ImageManager())->make(Arr::get($attributes, 'avatarUrl')); | ||
resolve(AvatarUploader::class)->upload($user, $image); | ||
} | ||
} | ||
} |