From cba50717a653be434c6bddf9cf00d9d3fc8e7200 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Sat, 7 Nov 2026 02:12:18 +0000 Subject: [PATCH 1/2] Only send the ids and types of replicator sets and grid rows to listings --- src/Fieldtypes/Grid.php | 15 ++++++ src/Fieldtypes/Replicator.php | 15 ++++++ .../Feature/Entries/ViewEntryListingTest.php | 46 +++++++++++++++++++ tests/Fieldtypes/GridTest.php | 10 ++++ tests/Fieldtypes/ReplicatorTest.php | 10 ++++ 5 files changed, 96 insertions(+) diff --git a/src/Fieldtypes/Grid.php b/src/Fieldtypes/Grid.php index cd4926c0b39..0eb40b4036f 100644 --- a/src/Fieldtypes/Grid.php +++ b/src/Fieldtypes/Grid.php @@ -115,6 +115,21 @@ private function processRow($row, $index) return Arr::removeNullValues($row); } + /** + * Listings only show how many rows there are, so only each row's id + * is sent rather than everything in it. + */ + public function preProcessIndex($data) + { + if (! is_array($data)) { + return $data; + } + + return array_map(function ($row) { + return is_array($row) ? Arr::only($row, [RowId::handle()]) : $row; + }, $data); + } + public function preProcess($data) { $data = collect($data); diff --git a/src/Fieldtypes/Replicator.php b/src/Fieldtypes/Replicator.php index 73e0bc0f48b..428fd1e9739 100644 --- a/src/Fieldtypes/Replicator.php +++ b/src/Fieldtypes/Replicator.php @@ -124,6 +124,21 @@ protected function processRow($row, $index) return Arr::removeNullValues($row); } + /** + * Listings only show how many sets there are, so only each set's id, + * type and enabled state are sent rather than everything in them. + */ + public function preProcessIndex($data) + { + if (! is_array($data)) { + return $data; + } + + return array_map(function ($set) { + return is_array($set) ? Arr::only($set, [RowId::handle(), 'type', 'enabled']) : $set; + }, $data); + } + public function preProcess($data) { return collect($data)->map(function ($row, $i) { diff --git a/tests/Feature/Entries/ViewEntryListingTest.php b/tests/Feature/Entries/ViewEntryListingTest.php index 0d36b634ddc..d1b36f00299 100644 --- a/tests/Feature/Entries/ViewEntryListingTest.php +++ b/tests/Feature/Entries/ViewEntryListingTest.php @@ -2,9 +2,11 @@ namespace Tests\Feature\Entries; +use Facades\Statamic\Fields\BlueprintRepository; use Facades\Tests\Factories\EntryFactory; use PHPUnit\Framework\Attributes\Test; use Statamic\Entries\Collection; +use Statamic\Facades\Blueprint; use Statamic\Facades\User; use Tests\FakesRoles; use Tests\PreventSavingStacheItemsToDisk; @@ -90,4 +92,48 @@ public function it_shows_only_entries_in_index_for_sites_user_can_access() $this->assertEquals($expected, $entries->pluck('slug')->all()); } + + #[Test] + public function it_only_lists_the_ids_and_types_of_replicator_sets_and_grid_rows() + { + $collection = tap(Collection::make('test'))->save(); + + $blueprint = Blueprint::makeFromFields([ + 'sets' => ['type' => 'replicator', 'listable' => true, 'sets' => ['main' => ['sets' => [ + 'text' => ['fields' => [['handle' => 'words', 'field' => ['type' => 'text']]]], + ]]]], + 'rows' => ['type' => 'grid', 'listable' => true, 'fields' => [ + ['handle' => 'words', 'field' => ['type' => 'text']], + ]], + ])->setHandle('test'); + + BlueprintRepository::partialMock(); + BlueprintRepository::shouldReceive('in')->with('collections/test')->andReturn(collect([$blueprint])); + + EntryFactory::collection($collection)->slug('one')->data([ + 'sets' => [ + ['id' => 'set-a', 'type' => 'text', 'words' => 'Lots of words'], + ['id' => 'set-b', 'type' => 'text', 'words' => 'More words', 'enabled' => false], + ], + 'rows' => [ + ['id' => 'row-a', 'words' => 'Lots of words'], + ['id' => 'row-b', 'words' => 'More words'], + ['id' => 'row-c', 'words' => 'Even more words'], + ], + ])->create(); + + $response = $this + ->actingAs(tap(User::make()->makeSuper())->save()) + ->get(cp_route('collections.entries.index', ['collection' => 'test', 'columns' => 'title,sets,rows'])) + ->assertOk(); + + $entry = $response->json('data.0'); + + $this->assertSame([ + ['id' => 'set-a', 'type' => 'text'], + ['id' => 'set-b', 'type' => 'text', 'enabled' => false], + ], $entry['sets']); + + $this->assertSame([['id' => 'row-a'], ['id' => 'row-b'], ['id' => 'row-c']], $entry['rows']); + } } diff --git a/tests/Fieldtypes/GridTest.php b/tests/Fieldtypes/GridTest.php index 97c0604f366..6d8da518df1 100644 --- a/tests/Fieldtypes/GridTest.php +++ b/tests/Fieldtypes/GridTest.php @@ -642,4 +642,14 @@ public function augment($value) $this->assertEquals('test.-1.words', $value['new']['words']['fieldPathPrefix']); $this->assertEquals('test.-1.words', $value['defaults']['words']); } + + #[Test] + public function it_preprocesses_for_the_index_without_the_contents() + { + $fieldtype = new Grid; + + $this->assertSame([['id' => 'a'], []], $fieldtype->preProcessIndex([['id' => 'a', 'words' => 'Hello'], ['words' => 'Hi']])); + $this->assertNull($fieldtype->preProcessIndex(null)); + $this->assertSame('not an array', $fieldtype->preProcessIndex('not an array')); + } } diff --git a/tests/Fieldtypes/ReplicatorTest.php b/tests/Fieldtypes/ReplicatorTest.php index 1f9b45c2da8..b621339ab09 100644 --- a/tests/Fieldtypes/ReplicatorTest.php +++ b/tests/Fieldtypes/ReplicatorTest.php @@ -1581,6 +1581,16 @@ private function fieldWithSet(string $set) ]); } + #[Test] + public function it_preprocesses_for_the_index_without_the_contents() + { + $fieldtype = new Replicator; + + $this->assertSame([['id' => 'a', 'type' => 'text', 'enabled' => false], ['type' => 'text']], $fieldtype->preProcessIndex([['id' => 'a', 'type' => 'text', 'words' => 'Hello', 'enabled' => false], ['type' => 'text', 'words' => 'Hi']])); + $this->assertNull($fieldtype->preProcessIndex(null)); + $this->assertSame('not an array', $fieldtype->preProcessIndex('not an array')); + } + public static function groupedSetsProvider() { return [ From 235aa3e26da9711a436654cfe5aac15016f2d094 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 20 Nov 2026 17:55:39 -0500 Subject: [PATCH 2/2] Send the count of replicator sets and grid rows to listings The listing cell only shows a count, so send the count itself rather than a trimmed array. The index components now check for null so an empty field still shows 0 sets / 0 rows. Co-Authored-By: Claude Opus 5.5 --- .../js/components/fieldtypes/grid/GridIndex.vue | 2 +- .../fieldtypes/replicator/ReplicatorIndex.vue | 2 +- src/Fieldtypes/Grid.php | 12 +----------- src/Fieldtypes/Replicator.php | 12 +----------- tests/Feature/Entries/ViewEntryListingTest.php | 10 +++------- tests/Fieldtypes/GridTest.php | 4 ++-- tests/Fieldtypes/ReplicatorTest.php | 4 ++-- 7 files changed, 11 insertions(+), 35 deletions(-) diff --git a/resources/js/components/fieldtypes/grid/GridIndex.vue b/resources/js/components/fieldtypes/grid/GridIndex.vue index e22ff2181c0..b4a67489484 100644 --- a/resources/js/components/fieldtypes/grid/GridIndex.vue +++ b/resources/js/components/fieldtypes/grid/GridIndex.vue @@ -1,5 +1,5 @@ diff --git a/resources/js/components/fieldtypes/replicator/ReplicatorIndex.vue b/resources/js/components/fieldtypes/replicator/ReplicatorIndex.vue index 6dfe2274c05..2d5f93f4bf3 100644 --- a/resources/js/components/fieldtypes/replicator/ReplicatorIndex.vue +++ b/resources/js/components/fieldtypes/replicator/ReplicatorIndex.vue @@ -1,5 +1,5 @@ diff --git a/src/Fieldtypes/Grid.php b/src/Fieldtypes/Grid.php index 0eb40b4036f..cf33caa06b4 100644 --- a/src/Fieldtypes/Grid.php +++ b/src/Fieldtypes/Grid.php @@ -115,19 +115,9 @@ private function processRow($row, $index) return Arr::removeNullValues($row); } - /** - * Listings only show how many rows there are, so only each row's id - * is sent rather than everything in it. - */ public function preProcessIndex($data) { - if (! is_array($data)) { - return $data; - } - - return array_map(function ($row) { - return is_array($row) ? Arr::only($row, [RowId::handle()]) : $row; - }, $data); + return is_array($data) ? count($data) : $data; } public function preProcess($data) diff --git a/src/Fieldtypes/Replicator.php b/src/Fieldtypes/Replicator.php index 428fd1e9739..4254825909a 100644 --- a/src/Fieldtypes/Replicator.php +++ b/src/Fieldtypes/Replicator.php @@ -124,19 +124,9 @@ protected function processRow($row, $index) return Arr::removeNullValues($row); } - /** - * Listings only show how many sets there are, so only each set's id, - * type and enabled state are sent rather than everything in them. - */ public function preProcessIndex($data) { - if (! is_array($data)) { - return $data; - } - - return array_map(function ($set) { - return is_array($set) ? Arr::only($set, [RowId::handle(), 'type', 'enabled']) : $set; - }, $data); + return is_array($data) ? count($data) : $data; } public function preProcess($data) diff --git a/tests/Feature/Entries/ViewEntryListingTest.php b/tests/Feature/Entries/ViewEntryListingTest.php index d1b36f00299..d3654dbbcfd 100644 --- a/tests/Feature/Entries/ViewEntryListingTest.php +++ b/tests/Feature/Entries/ViewEntryListingTest.php @@ -94,7 +94,7 @@ public function it_shows_only_entries_in_index_for_sites_user_can_access() } #[Test] - public function it_only_lists_the_ids_and_types_of_replicator_sets_and_grid_rows() + public function it_only_lists_the_counts_of_replicator_sets_and_grid_rows() { $collection = tap(Collection::make('test'))->save(); @@ -129,11 +129,7 @@ public function it_only_lists_the_ids_and_types_of_replicator_sets_and_grid_rows $entry = $response->json('data.0'); - $this->assertSame([ - ['id' => 'set-a', 'type' => 'text'], - ['id' => 'set-b', 'type' => 'text', 'enabled' => false], - ], $entry['sets']); - - $this->assertSame([['id' => 'row-a'], ['id' => 'row-b'], ['id' => 'row-c']], $entry['rows']); + $this->assertSame(2, $entry['sets']); + $this->assertSame(3, $entry['rows']); } } diff --git a/tests/Fieldtypes/GridTest.php b/tests/Fieldtypes/GridTest.php index 6d8da518df1..1964b0430d0 100644 --- a/tests/Fieldtypes/GridTest.php +++ b/tests/Fieldtypes/GridTest.php @@ -644,11 +644,11 @@ public function augment($value) } #[Test] - public function it_preprocesses_for_the_index_without_the_contents() + public function it_preprocesses_for_the_index_as_a_row_count() { $fieldtype = new Grid; - $this->assertSame([['id' => 'a'], []], $fieldtype->preProcessIndex([['id' => 'a', 'words' => 'Hello'], ['words' => 'Hi']])); + $this->assertSame(2, $fieldtype->preProcessIndex([['id' => 'a', 'words' => 'Hello'], ['words' => 'Hi']])); $this->assertNull($fieldtype->preProcessIndex(null)); $this->assertSame('not an array', $fieldtype->preProcessIndex('not an array')); } diff --git a/tests/Fieldtypes/ReplicatorTest.php b/tests/Fieldtypes/ReplicatorTest.php index b621339ab09..674948ce93f 100644 --- a/tests/Fieldtypes/ReplicatorTest.php +++ b/tests/Fieldtypes/ReplicatorTest.php @@ -1582,11 +1582,11 @@ private function fieldWithSet(string $set) } #[Test] - public function it_preprocesses_for_the_index_without_the_contents() + public function it_preprocesses_for_the_index_as_a_set_count() { $fieldtype = new Replicator; - $this->assertSame([['id' => 'a', 'type' => 'text', 'enabled' => false], ['type' => 'text']], $fieldtype->preProcessIndex([['id' => 'a', 'type' => 'text', 'words' => 'Hello', 'enabled' => false], ['type' => 'text', 'words' => 'Hi']])); + $this->assertSame(2, $fieldtype->preProcessIndex([['id' => 'a', 'type' => 'text', 'words' => 'Hello', 'enabled' => false], ['type' => 'text', 'words' => 'Hi']])); $this->assertNull($fieldtype->preProcessIndex(null)); $this->assertSame('not an array', $fieldtype->preProcessIndex('not an array')); }