diff --git a/src/Http/Controllers/CP/Fieldtypes/ReplicatorSetController.php b/src/Http/Controllers/CP/Fieldtypes/ReplicatorSetController.php index b4f4c56e702..c3e9f008b19 100644 --- a/src/Http/Controllers/CP/Fieldtypes/ReplicatorSetController.php +++ b/src/Http/Controllers/CP/Fieldtypes/ReplicatorSetController.php @@ -71,7 +71,7 @@ private function getReplicatorField(Blueprint $blueprint, string $field): Field private function getConfig(array $config, array $remainingFieldPathComponents): array { - $isGroupOrGrid = isset($config['type']) && in_array($config['type'], ['group', 'grid']); + $isGroupOrGrid = isset($config['fields']); $isReplicator = isset($config['type']) && in_array($config['type'], ['bard', 'replicator']); if ($isReplicator) { diff --git a/tests/Fieldtypes/ReplicatorTest.php b/tests/Fieldtypes/ReplicatorTest.php index 7d2a2b097f5..06d12b95766 100644 --- a/tests/Fieldtypes/ReplicatorTest.php +++ b/tests/Fieldtypes/ReplicatorTest.php @@ -1105,6 +1105,72 @@ public function it_can_return_set_defaults_for_replicator_inside_grid() ], $response->json('new')); } + #[Test] + public function it_can_return_set_defaults_for_replicator_inside_custom_fieldtype() + { + $this->partialMock(RowId::class, function (MockInterface $mock) { + $mock->shouldReceive('generate')->andReturn('random-string-1', 'random-string-2'); + }); + + $blueprint = Facades\Blueprint::make()->setHandle('default')->setNamespace('collections.pages'); + $blueprint->setContents([ + 'sections' => [ + 'main' => [ + 'fields' => [ + [ + 'handle' => 'stuff', + 'field' => [ + 'type' => 'custom_fieldtype', + 'fields' => [ + [ + 'handle' => 'content_blocks', + 'field' => [ + 'type' => 'replicator', + 'sets' => [ + 'text' => [ + 'fields' => [ + [ + 'handle' => 'body', + 'field' => [ + 'type' => 'textarea', + 'default' => 'the default', + ], + ], + ], + ], + ], + ], + ], + ], + ], + ], + ], + ], + ], + ]); + + Facades\Blueprint::partialMock(); + Facades\Blueprint::shouldReceive('find')->with('collections.pages.default')->andReturn($blueprint); + + $response = $this + ->actingAs(tap(Facades\User::make()->makeSuper())->save()) + ->postJson(cp_route('replicator-fieldtype.set'), [ + 'blueprint' => 'collections.pages.default', + 'field' => 'stuff.content_blocks', + 'set' => 'text', + ]) + ->assertOk(); + + $this->assertEquals([ + 'body' => 'the default', + ], $response->json('defaults')); + + $this->assertEquals([ + '_' => '_', + 'body' => null, + ], $response->json('new')); + } + #[Test] public function it_can_return_set_defaults_when_sets_are_stored_in_legacy_format() {