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)));
+13
View File
@@ -133,6 +133,19 @@ public function test_editor_reorders_and_duplicates_sections(): void
$this->assertCount(5, array_unique(array_column($revision->sections, 'id')), 'Ein duplizierter Abschnitt erhält eine eigene Kennung.');
}
public function test_duplicate_action_places_the_copy_right_after_the_section(): void
{
$page = Page::query()->where('path', '/')->firstOrFail();
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
$keys = array_keys($component->get('data.sections'));
$component->callAction(TestAction::make('clone')->schemaComponent('sections')->arguments(['item' => $keys[1]]));
$this->assertSame(['heading', 'prose', 'prose', 'cards', 'call_to_action'], $this->widgetTypes($component->get('data.sections')));
$component->call('save')->assertHasNoFormErrors();
$this->assertSame(['heading', 'prose', 'prose', 'cards', 'call_to_action'], array_column($page->fresh()->latestRevision->blocks, 'type'));
}
public function test_layout_change_keeps_widgets_and_rejects_layouts_with_too_few_slots(): void
{
$page = Page::query()->where('path', '/')->firstOrFail();
+9
View File
@@ -239,6 +239,15 @@ public function test_style_summary_names_background_and_divider(): void
$this->assertSame('Dunkle Markenfläche · Breit · Trenner: Dezente Linie', SectionStyle::summary(['background' => 'dark', 'width' => 'wide', 'divider' => 'line']));
}
public function test_duplicated_section_is_inserted_right_after_its_original(): void
{
$items = ['a' => ['n' => 1], 'b' => ['n' => 2], 'c' => ['n' => 3]];
$this->assertSame(['a', 'b', 'kopie', 'c'], array_keys(SectionEditor::insertCopyAfter($items, 'b', 'kopie')));
$this->assertSame(['n' => 2], SectionEditor::insertCopyAfter($items, 'b', 'kopie')['kopie']);
$this->assertSame($items, SectionEditor::insertCopyAfter($items, 'fehlt', 'kopie'));
}
public function test_layout_change_in_the_editor_never_drops_a_widget(): void
{
$slots = [