Skip to content

Commit

Permalink
Merge pull request #7 from helsingborg-stad/feat/acfGetFields
Browse files Browse the repository at this point in the history
feat: add acfGetFields function
  • Loading branch information
sebastianthulin authored Jan 22, 2025
2 parents 7efd89e + 6b4baf8 commit 336839d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
Binary file added src/.DS_Store
Binary file not shown.
15 changes: 15 additions & 0 deletions src/Contracts/AcfGetFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace AcfService\Contracts;

interface AcfGetFields
{
/**
* Retrieves all the fields from a specific field group.
*
* @param string $parent The field group’s ID or key.
*/
public function acfGetFields(
string|array $parent
): array;
}
9 changes: 9 additions & 0 deletions src/Implementations/FakeAcfService.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,13 @@ public function addOptionsSubPage(array $options): void
{
$this->registerFunctionCall(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function acfGetFields(string|array $parent): array
{
$this->registerFunctionCall(__FUNCTION__, func_get_args());
return $this->getReturnValue(__FUNCTION__, func_get_args(), []);
}
}
12 changes: 12 additions & 0 deletions src/Implementations/FakeAcfService.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,16 @@ public function testAddOptionsSubPage()

$this->assertEquals([['testOptions']], $fakeAcfService->methodCalls['addOptionsSubPage'][0]);
}

/**
* @testdox acfGetFields()
*/
public function testAcfGetFields()
{
$fakeAcfService = new FakeAcfService();

$fakeAcfService->acfGetFields('testParent');

$this->assertEquals(['testParent'], $fakeAcfService->methodCalls['acfGetFields'][0]);
}
}
8 changes: 8 additions & 0 deletions src/Implementations/NativeAcfService.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,12 @@ public function addOptionsSubPage(array $options): void
{
acf_add_options_sub_page($options);
}

/**
* @inheritDoc
*/
public function acfGetFields(string|array $parent): array
{
return acf_get_fields($parent);
}
}

0 comments on commit 336839d

Please sign in to comment.