Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
57 lines
2.3 KiB
PHP
57 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\SettingsResource\Schemas;
|
|
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Schemas\Schema;
|
|
|
|
class SettingsForm
|
|
{
|
|
public static function configure(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
Section::make(__('panel.settings.sections.general'))
|
|
->schema([
|
|
TextInput::make('key')
|
|
->label(__('panel.settings.fields.key'))
|
|
->disabled()
|
|
->columnSpanFull(),
|
|
|
|
/*
|
|
* Raw JSON rather than a key/value editor.
|
|
*
|
|
* A setting holds whatever it holds: `site.maintenance` is
|
|
* a map containing another map of translations. A
|
|
* key/value grid can only show one flat level, so it would
|
|
* render the nested part as text and write that text back
|
|
* on save — quietly destroying every translation of the
|
|
* maintenance notice.
|
|
*
|
|
* Showing the value as it really is cannot lie about it,
|
|
* and the `json` rule means a typo is refused rather than
|
|
* stored.
|
|
*/
|
|
Textarea::make('value')
|
|
->label(__('panel.settings.fields.value'))
|
|
->helperText(__('panel.settings.fields.value_hint'))
|
|
->rows(12)
|
|
->columnSpanFull()
|
|
->extraInputAttributes(['class' => 'font-mono text-sm'])
|
|
->rule('json')
|
|
->formatStateUsing(fn (mixed $state): string => json_encode(
|
|
$state,
|
|
JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES,
|
|
) ?: 'null')
|
|
->dehydrateStateUsing(fn (?string $state): mixed => json_decode(
|
|
(string) $state,
|
|
associative: true,
|
|
)),
|
|
]),
|
|
]);
|
|
}
|
|
}
|