Resolve author avatar via Filament avatar provider#110
Open
ItsMalikJones wants to merge 4 commits into
Open
Conversation
Adds an `avatar_provider` config key and a fallback chain in
`Comment::getAuthorAvatar()`:
1. `HasAvatar::getFilamentAvatarUrl()` (existing behavior)
2. `config('commentions.avatar_provider')` if set
3. Current Filament panel's `getDefaultAvatarProvider()` if a
panel is active
4. ui-avatars.com fallback (existing behavior)
Any class exposing `get(Model|Authenticatable $user): string`
works — including Filament's first-party `GravatarProvider`
and `UiAvatarsProvider`.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #49.
Currently
Comment::getAuthorAvatar()only checks whether the author implements Filament'sHasAvatarcontract; if not, it jumps straight to a hard-codedui-avatars.comURL. This ignores any avatar provider the host application has already configured on its Filament panel (e.g. Gravatar), forcing every non-HasAvataruser to render the generic initials avatar.This PR adds an avatar provider resolution step so Commentions respects the application's existing avatar configuration before falling back.
Resolution chain
getAuthorAvatar()now resolves in this order:HasAvatar::getFilamentAvatarUrl()— existing behavior, returned if non-nullconfig('commentions.avatar_provider')— a provider class explicitly configured for the packagegetDefaultAvatarProvider()— only when a panel is in contextui-avatars.com— existing final fallbackAny class exposing
get(Model|Authenticatable $user): stringworks, including Filament's first-partyGravatarProviderandUiAvatarsProvider.Changes
config/commentions.php— new nullableavatar_providerkey, documented inline.src/Config.php—getAvatarProvider(): ?stringaccessor, following the existingConfigpattern.src/Comment.php— extractedresolveAvatarFromProvider(); panel lookup is guarded byFilament::getCurrentPanel() !== nulland wrapped in atry/catchso the package degrades gracefully (back to theui-avatars.comfallback) outside a panel context or on misconfiguration.README.md— documents the new config option and the default panel-provider behavior.tests/AvatarProviderTest.php+tests/Models/StubAvatarProvider.php— cover the no-provider fallback and the explicitly-configured-provider paths.