Loheide-eu-mitarbeiterplatt.../app/Filament/AvatarProviders/InitialsAvatarProvider.php
Friederich Loheide 4d855c8a74
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m29s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m38s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m40s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m7s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m13s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m24s
QM: Wiedervorlage und Lesebestätigung, Platzhalter für Profilbilder (0.21.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 07:36:47 +00:00

43 lines
1.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Filament\AvatarProviders;
use App\Models\User;
use App\Support\Branding;
use Filament\AvatarProviders\Contracts\AvatarProvider;
use Filament\Facades\Filament;
use Illuminate\Database\Eloquent\Model;
/**
* Initialen-Avatar als eingebettetes SVG. Ersetzt Filaments Standard, der die
* Bilder von ui-avatars.com lädt – personenbezogene Daten gehen so nicht an Dritte.
*/
class InitialsAvatarProvider implements AvatarProvider
{
public function __construct(private readonly Branding $branding) {}
public function get(Model $record): string
{
if ($placeholder = $this->branding->url($this->branding->active()['avatar_placeholder'] ?? null)) {
return $placeholder;
}
$initials = $record instanceof User
? $record->initials
: mb_strtoupper(mb_substr(Filament::getNameForDefaultAvatar($record), 0, 1));
$palette = $this->branding->palette();
$background = $palette[100];
$foreground = $palette[800];
$svg = sprintf(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" fill="%s"/>'
.'<text x="50%%" y="50%%" dy=".35em" text-anchor="middle" font-family="Inter, system-ui, sans-serif" font-size="26" font-weight="600" fill="%s">%s</text></svg>',
$background,
$foreground,
htmlspecialchars($initials, ENT_XML1),
);
return 'data:image/svg+xml;base64,'.base64_encode($svg);
}
}