feat(filament): default performance items to 1 (#1216)

This commit is contained in:
Kyrch
2026-07-10 18:11:57 -03:00
committed by GitHub
parent 5dcad93fab
commit fec8c51dda
2 changed files with 7 additions and 5 deletions
@@ -58,17 +58,19 @@ class PerformanceForm
->live(true) ->live(true)
->key('song.performances') ->key('song.performances')
->collapsible() ->collapsible()
->defaultItems(0) ->defaultItems(1)
->columns(3) ->columns(3)
->columnSpanFull() ->columnSpanFull()
->reorderableWithButtons() ->reorderableWithButtons()
->formatStateUsing(function ($livewire, Get $get): array { ->formatStateUsing(function ($livewire, Get $get, array $state): array {
/** @var Song|null $song */ /** @var Song|null $song */
$song = $livewire instanceof PerformanceSongRelationManager $song = $livewire instanceof PerformanceSongRelationManager
? $livewire->getOwnerRecord() ? $livewire->getOwnerRecord()
: Song::query()->find($get(Performance::ATTRIBUTE_SONG)); : Song::query()->find($get(Performance::ATTRIBUTE_SONG));
return PerformanceSongRelationManager::formatArtists($song); $artists = PerformanceSongRelationManager::formatArtists($song);
return blank($artists) ? $state : $artists;
}) })
->schema([ ->schema([
BelongsTo::make(Artist::ATTRIBUTE_ID) BelongsTo::make(Artist::ATTRIBUTE_ID)
@@ -110,7 +112,7 @@ class PerformanceForm
->helperText(__('filament.fields.performance.member_alias.help')), ->helperText(__('filament.fields.performance.member_alias.help')),
]), ]),
]) ])
->saveRelationshipsUsing(fn (Get $get, ?array $state) => PerformanceSongRelationManager::saveArtists(intval($get(Performance::ATTRIBUTE_SONG)), $state)), ->saveRelationshipsUsing(fn (Get $get, ?array $state) => PerformanceSongRelationManager::saveArtists($get(Performance::ATTRIBUTE_SONG), $state)),
]; ];
} }
} }
@@ -89,7 +89,7 @@ class PerformanceSongRelationManager extends PerformanceRelationManager
/** /**
* Save the artists to the action. * Save the artists to the action.
*/ */
public static function saveArtists(Song|int|null $song = null, ?array $performances = []): void public static function saveArtists(Song|int|null $song = null, array $performances = []): void
{ {
if (is_null($song) || blank($performances)) { if (is_null($song) || blank($performances)) {
return; return;