Füge duplizierte Abschnitte direkt hinter dem Original ein.
CI Feature / test (push) Successful in 34s
Deploy Test / test (push) Successful in 30s
Deploy Test / deploy (push) Successful in 28s

Filament hängt eine Kopie sonst ans Seitenende; auf langen Seiten war sie dort
schwer zu finden. Gefunden in der Browserprüfung.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-17 21:10:22 +01:00
1 parent 4cad60259a
commit 6152451e2e
3 files changed
+54 -1

No files matched your search

+32 -1
View File
@@ -49,7 +49,14 @@ public static function repeater(string $name = 'sections'): Repeater
->collapsible()
->deletable()
->maxItems(PageSections::MAX_SECTIONS)
->cloneAction(fn (Action $action): Action => $action->tooltip('Abschnitt duplizieren'))
->cloneAction(fn (Action $action): Action => $action
->tooltip('Abschnitt duplizieren')
->action(function (array $arguments, Repeater $component): void {
// Die Kopie steht direkt hinter dem Original (Filament hängt sie sonst ans Seitenende).
$component->rawState(self::insertCopyAfter($component->getRawState() ?? [], (string) $arguments['item'], (string) $component->generateUuid()));
$component->callAfterStateUpdated();
$component->shouldPartiallyRenderAfterActionsCalled() ? $component->partiallyRender() : null;
}))
->deleteAction(fn (Action $action): Action => $action
->tooltip('Abschnitt löschen')
->requiresConfirmation()
@@ -413,6 +420,30 @@ public static function arrangeSlots(mixed $slots, string $layout): array
return $arranged;
}
/**
* Fügt die Kopie eines Abschnitts direkt hinter dem Original ein. Kennungen bleiben gleich; beim Speichern
* behält das Original seine Kennungen und die Kopie erhält neue.
*
* @param array<string, mixed> $items
* @return array<string, mixed>
*/
public static function insertCopyAfter(array $items, string $key, string $newKey): array
{
if (! array_key_exists($key, $items)) {
return $items;
}
$result = [];
foreach ($items as $itemKey => $item) {
$result[$itemKey] = $item;
if ((string) $itemKey === $key) {
$result[$newKey] = $item;
}
}
return $result;
}
public static function filledCount(mixed $slots): int
{
return count(array_filter(is_array($slots) ? $slots : [], fn ($slot): bool => self::slotHasWidget($slot)));