Skip to content

Resolve author avatar via Filament avatar provider#110

Open
ItsMalikJones wants to merge 4 commits into
mainfrom
feat/49-default-avatar-provider
Open

Resolve author avatar via Filament avatar provider#110
ItsMalikJones wants to merge 4 commits into
mainfrom
feat/49-default-avatar-provider

Conversation

@ItsMalikJones
Copy link
Copy Markdown
Contributor

Summary

Closes #49.

Currently Comment::getAuthorAvatar() only checks whether the author implements Filament's HasAvatar contract; if not, it jumps straight to a hard-coded ui-avatars.com URL. This ignores any avatar provider the host application has already configured on its Filament panel (e.g. Gravatar), forcing every non-HasAvatar user 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:

  1. HasAvatar::getFilamentAvatarUrl() — existing behavior, returned if non-null
  2. config('commentions.avatar_provider') — a provider class explicitly configured for the package
  3. The active Filament panel's getDefaultAvatarProvider() — only when a panel is in context
  4. ui-avatars.com — existing final fallback

Any class exposing get(Model|Authenticatable $user): string works, including Filament's first-party GravatarProvider and UiAvatarsProvider.

Changes

  • config/commentions.php — new nullable avatar_provider key, documented inline.
  • src/Config.phpgetAvatarProvider(): ?string accessor, following the existing Config pattern.
  • src/Comment.php — extracted resolveAvatarFromProvider(); panel lookup is guarded by Filament::getCurrentPanel() !== null and wrapped in a try/catch so the package degrades gracefully (back to the ui-avatars.com fallback) 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.

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`.
@ItsMalikJones ItsMalikJones self-assigned this Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement default avatar provider

1 participant