diff --git a/src/Fields/Fieldset.php b/src/Fields/Fieldset.php index 98bfbb16aa..44e43ddd9e 100644 --- a/src/Fields/Fieldset.php +++ b/src/Fields/Fieldset.php @@ -108,6 +108,11 @@ public function field(string $handle): ?Field return $this->fields()->get($handle); } + public function hasField($field) + { + return $this->fields()->has($field); + } + public function isNamespaced(): bool { return Str::contains($this->handle(), '::'); diff --git a/tests/Fields/FieldsetTest.php b/tests/Fields/FieldsetTest.php index 4fef1e73fc..ff8fb006d0 100644 --- a/tests/Fields/FieldsetTest.php +++ b/tests/Fields/FieldsetTest.php @@ -167,6 +167,32 @@ public function gets_a_single_field() $this->assertNull($fieldset->field('unknown')); } + #[Test] + public function it_can_check_if_has_field() + { + FieldsetRepository::shouldReceive('find') + ->with('partial') + ->andReturn((new Fieldset)->setContents([ + 'fields' => [ + ['handle' => 'two', 'field' => ['type' => 'text']], + ], + ])) + ->once(); + + $fieldset = new Fieldset; + + $fieldset->setContents([ + 'fields' => [ + ['handle' => 'one', 'field' => ['type' => 'text']], + ['import' => 'partial'], + ], + ]); + + $this->assertTrue($fieldset->hasField('one')); + $this->assertTrue($fieldset->hasField('two')); + $this->assertFalse($fieldset->hasField('three')); + } + #[Test] public function gets_blueprints_importing_fieldset() {