|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace FlexKleks\PasteFoxShare; |
| 4 | + |
| 5 | +use App\Contracts\Plugins\HasPluginSettings; |
| 6 | +use App\Traits\EnvironmentWriterTrait; |
| 7 | +use Filament\Contracts\Plugin; |
| 8 | +use Filament\Forms\Components\Select; |
| 9 | +use Filament\Forms\Components\TextInput; |
| 10 | +use Filament\Notifications\Notification; |
| 11 | +use Filament\Panel; |
| 12 | +use Filament\Schemas\Components\Section; |
| 13 | + |
| 14 | +class PasteFoxSharePlugin implements HasPluginSettings, Plugin |
| 15 | +{ |
| 16 | + use EnvironmentWriterTrait; |
| 17 | + |
| 18 | + public function getId(): string |
| 19 | + { |
| 20 | + return 'pastefox-share'; |
| 21 | + } |
| 22 | + |
| 23 | + public function register(Panel $panel): void {} |
| 24 | + |
| 25 | + public function boot(Panel $panel): void {} |
| 26 | + |
| 27 | + public function getSettingsForm(): array |
| 28 | + { |
| 29 | + return [ |
| 30 | + Section::make(trans('pastefox-share::messages.section_api')) |
| 31 | + ->description(trans('pastefox-share::messages.section_api_description')) |
| 32 | + ->schema([ |
| 33 | + TextInput::make('api_key') |
| 34 | + ->label(trans('pastefox-share::messages.api_key')) |
| 35 | + ->password() |
| 36 | + ->revealable() |
| 37 | + ->helperText(trans('pastefox-share::messages.api_key_helper')) |
| 38 | + ->default(fn () => config('pastefox-share.api_key')), |
| 39 | + ]), |
| 40 | + |
| 41 | + Section::make(trans('pastefox-share::messages.section_paste')) |
| 42 | + ->schema([ |
| 43 | + Select::make('visibility') |
| 44 | + ->label(trans('pastefox-share::messages.visibility')) |
| 45 | + ->options([ |
| 46 | + 'PUBLIC' => trans('pastefox-share::messages.visibility_public'), |
| 47 | + 'PRIVATE' => trans('pastefox-share::messages.visibility_private'), |
| 48 | + ]) |
| 49 | + ->default(fn () => config('pastefox-share.visibility', 'PUBLIC')) |
| 50 | + ->helperText(trans('pastefox-share::messages.visibility_helper')), |
| 51 | + |
| 52 | + Select::make('effect') |
| 53 | + ->label(trans('pastefox-share::messages.effect')) |
| 54 | + ->options([ |
| 55 | + 'NONE' => trans('pastefox-share::messages.effect_none'), |
| 56 | + 'MATRIX' => trans('pastefox-share::messages.effect_matrix'), |
| 57 | + 'GLITCH' => trans('pastefox-share::messages.effect_glitch'), |
| 58 | + 'CONFETTI' => trans('pastefox-share::messages.effect_confetti'), |
| 59 | + 'SCRATCH' => trans('pastefox-share::messages.effect_scratch'), |
| 60 | + 'PUZZLE' => trans('pastefox-share::messages.effect_puzzle'), |
| 61 | + 'SLOTS' => trans('pastefox-share::messages.effect_slots'), |
| 62 | + 'SHAKE' => trans('pastefox-share::messages.effect_shake'), |
| 63 | + 'FIREWORKS' => trans('pastefox-share::messages.effect_fireworks'), |
| 64 | + 'TYPEWRITER' => trans('pastefox-share::messages.effect_typewriter'), |
| 65 | + 'BLUR' => trans('pastefox-share::messages.effect_blur'), |
| 66 | + ]) |
| 67 | + ->default(fn () => config('pastefox-share.effect', 'NONE')), |
| 68 | + |
| 69 | + Select::make('theme') |
| 70 | + ->label(trans('pastefox-share::messages.theme')) |
| 71 | + ->options([ |
| 72 | + 'dark' => trans('pastefox-share::messages.theme_dark'), |
| 73 | + 'light' => trans('pastefox-share::messages.theme_light'), |
| 74 | + ]) |
| 75 | + ->default(fn () => config('pastefox-share.theme', 'dark')), |
| 76 | + |
| 77 | + TextInput::make('password') |
| 78 | + ->label(trans('pastefox-share::messages.password')) |
| 79 | + ->password() |
| 80 | + ->revealable() |
| 81 | + ->minLength(4) |
| 82 | + ->maxLength(100) |
| 83 | + ->helperText(trans('pastefox-share::messages.password_helper')) |
| 84 | + ->default(fn () => config('pastefox-share.password')), |
| 85 | + ]), |
| 86 | + ]; |
| 87 | + } |
| 88 | + |
| 89 | + public function saveSettings(array $data): void |
| 90 | + { |
| 91 | + $this->writeToEnvironment([ |
| 92 | + 'PASTEFOX_API_KEY' => $data['api_key'] ?? '', |
| 93 | + 'PASTEFOX_VISIBILITY' => $data['visibility'] ?? 'PUBLIC', |
| 94 | + 'PASTEFOX_EFFECT' => $data['effect'] ?? 'NONE', |
| 95 | + 'PASTEFOX_THEME' => $data['theme'] ?? 'dark', |
| 96 | + 'PASTEFOX_PASSWORD' => $data['password'] ?? '', |
| 97 | + ]); |
| 98 | + |
| 99 | + Notification::make() |
| 100 | + ->title(trans('pastefox-share::messages.settings_saved')) |
| 101 | + ->success() |
| 102 | + ->send(); |
| 103 | + } |
| 104 | +} |
0 commit comments