Files
fotospiel-app/app/Filament/SuperAdmin/Pages/WatermarkSettingsPage.php
Codex Agent 6ca3c03179
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
Fix watermark settings form schema
2026-01-01 20:42:03 +01:00

137 lines
4.2 KiB
PHP
Raw 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\SuperAdmin\Pages;
use App\Filament\Clusters\RareAdmin\RareAdminCluster;
use App\Models\WatermarkSetting;
use Filament\Forms;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Schema;
class WatermarkSettingsPage extends Page
{
protected static null|string|\BackedEnum $navigationIcon = 'heroicon-o-sparkles';
protected static ?string $cluster = RareAdminCluster::class;
protected string $view = 'filament.super-admin.pages.watermark-settings-page';
protected static null|string|\UnitEnum $navigationGroup = null;
protected static ?int $navigationSort = 20;
public static function getNavigationGroup(): \UnitEnum|string|null
{
return __('admin.nav.branding');
}
public ?string $asset = null;
public string $position = 'bottom-right';
public float $opacity = 0.25;
public float $scale = 0.2;
public int $padding = 16;
public int $offset_x = 0;
public int $offset_y = 0;
public function mount(): void
{
$settings = WatermarkSetting::query()->first();
if ($settings) {
$this->asset = $settings->asset;
$this->position = $settings->position;
$this->opacity = (float) $settings->opacity;
$this->scale = (float) $settings->scale;
$this->padding = (int) $settings->padding;
$this->offset_x = (int) ($settings->offset_x ?? 0);
$this->offset_y = (int) ($settings->offset_y ?? 0);
}
}
public function form(Schema $schema): Schema
{
return $schema->schema([
Forms\Components\FileUpload::make('asset')
->label('Basis-Wasserzeichen (PNG/SVG empfohlen)')
->disk('public')
->directory('branding')
->preserveFilenames()
->image()
->required(),
Forms\Components\Select::make('position')
->label('Position')
->options([
'top-left' => 'Oben links',
'top-right' => 'Oben rechts',
'bottom-left' => 'Unten links',
'bottom-right' => 'Unten rechts',
'center' => 'Zentriert',
])
->required(),
Forms\Components\TextInput::make('opacity')
->label('Opacity (01)')
->numeric()
->minValue(0)
->maxValue(1)
->step(0.05)
->default(0.25)
->required(),
Forms\Components\TextInput::make('scale')
->label('Skalierung (01, relativ zur Bildbreite)')
->numeric()
->minValue(0.05)
->maxValue(1)
->step(0.05)
->default(0.2)
->required(),
Forms\Components\TextInput::make('padding')
->label('Padding (px)')
->numeric()
->minValue(0)
->default(16)
->required(),
Forms\Components\TextInput::make('offset_x')
->label('Offset X (px)')
->numeric()
->minValue(-500)
->maxValue(500)
->default(0)
->required(),
Forms\Components\TextInput::make('offset_y')
->label('Offset Y (px)')
->numeric()
->minValue(-500)
->maxValue(500)
->default(0)
->required(),
])->columns(2);
}
public function save(): void
{
$this->validate();
$settings = WatermarkSetting::query()->firstOrNew([]);
$settings->asset = $this->asset;
$settings->position = $this->position;
$settings->opacity = $this->opacity;
$settings->scale = $this->scale;
$settings->padding = $this->padding;
$settings->offset_x = $this->offset_x;
$settings->offset_y = $this->offset_y;
$settings->save();
Notification::make()
->title('Wasserzeichen aktualisiert')
->success()
->send();
}
}