Accept the option picked in selects of translatable records
Some checks failed
Tests / lint (push) Has been cancelled
Tests / test (push) Has been cancelled
Tests / test-postgres (push) Has been cancelled
Tests / mcp (push) Has been cancelled

Saving a page with a category failed with "El campo categoría no está
en la lista de valores permitidos" — for every category, not only the
one being tried. Filament builds such a list through a query, which
handles `->relationship('category', 'name->es')`, but validates a choice
by reading the title back off the record as a property,
`$record->{'name->es'}`, which does not exist. No label, so every
option was refused.

The same pattern was in seven more places: a call's, a testimonial's,
a talk's and a repository's project, a testimonial's service, and the
page and application filters. TranslatedOptionLabel gives Filament the
record's own translation instead, in the language of whoever uses the
panel; the JSON path stays for search and ordering.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 21:21:43 +02:00
parent 82ef2b38dd
commit 3daa40570b
9 changed files with 138 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ namespace App\Filament\Resources\Pages\Schemas;
use App\Enums\PageStatus;
use App\Filament\Resources\Pages\PageResource;
use App\Filament\Support\TranslatableTabs;
use App\Filament\Support\TranslatedOptionLabel;
use App\Models\Page;
use App\Rules\UniqueTranslatedSlug;
use App\Support\DuplicateTitles;
@@ -112,6 +113,7 @@ class PageForm
Select::make('category_id')
->label(__('panel.pages.fields.category'))
->relationship('category', 'name->'.config('locales.default'))
->getOptionLabelFromRecordUsing(TranslatedOptionLabel::using('name'))
->searchable()
->preload(),

View File

@@ -8,6 +8,7 @@ use App\Enums\PageStatus;
use App\Filament\Support\PreviewAction;
use App\Filament\Support\ReviewActions;
use App\Filament\Support\ReviewStatusColumn;
use App\Filament\Support\TranslatedOptionLabel;
use App\Filament\Support\TranslationStatusColumn;
use App\Filament\Support\ViewsColumn;
use App\Models\Page;
@@ -127,6 +128,7 @@ class PagesTable
SelectFilter::make('category')
->label(__('panel.pages.fields.category'))
->relationship('category', 'name->'.config('locales.default'))
->getOptionLabelFromRecordUsing(TranslatedOptionLabel::using('name'))
->searchable()
->preload(),