Skip to content

Commit 7fd5d4e

Browse files
[5.x] Add hasField method to Fieldset (#11882)
1 parent 5bc591e commit 7fd5d4e

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/Fields/Fieldset.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public function field(string $handle): ?Field
108108
return $this->fields()->get($handle);
109109
}
110110

111+
public function hasField($field)
112+
{
113+
return $this->fields()->has($field);
114+
}
115+
111116
public function isNamespaced(): bool
112117
{
113118
return Str::contains($this->handle(), '::');

tests/Fields/FieldsetTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,32 @@ public function gets_a_single_field()
167167
$this->assertNull($fieldset->field('unknown'));
168168
}
169169

170+
#[Test]
171+
public function it_can_check_if_has_field()
172+
{
173+
FieldsetRepository::shouldReceive('find')
174+
->with('partial')
175+
->andReturn((new Fieldset)->setContents([
176+
'fields' => [
177+
['handle' => 'two', 'field' => ['type' => 'text']],
178+
],
179+
]))
180+
->once();
181+
182+
$fieldset = new Fieldset;
183+
184+
$fieldset->setContents([
185+
'fields' => [
186+
['handle' => 'one', 'field' => ['type' => 'text']],
187+
['import' => 'partial'],
188+
],
189+
]);
190+
191+
$this->assertTrue($fieldset->hasField('one'));
192+
$this->assertTrue($fieldset->hasField('two'));
193+
$this->assertFalse($fieldset->hasField('three'));
194+
}
195+
170196
#[Test]
171197
public function gets_blueprints_importing_fieldset()
172198
{

0 commit comments

Comments
 (0)