Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use n5s\PageForCustomPostType\Core\RewriteManager;
use n5s\PageForCustomPostType\Frontend\Handler;
use n5s\PageForCustomPostType\Frontend\QueryFilter;
use n5s\PageForCustomPostType\Integration\AdvancedCustomFields;
use n5s\PageForCustomPostType\Integration\Autodescription;
use n5s\PageForCustomPostType\Integration\Polylang;
use n5s\PageForCustomPostType\Integration\WordPressSeo;
Expand Down Expand Up @@ -141,6 +142,7 @@ public function __construct()
),

// Integration composites
AdvancedCustomFields\AdvancedCustomFields::class => static fn (): AdvancedCustomFields\AdvancedCustomFields => new AdvancedCustomFields\AdvancedCustomFields(),
Polylang\Polylang::class => fn (): Polylang\Polylang => new Polylang\Polylang(
$this->get(Polylang\UrlTranslation::class),
$this->get(Polylang\Translation::class),
Expand Down
36 changes: 28 additions & 8 deletions src/Integration/AdvancedCustomFields/AdvancedCustomFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@

namespace n5s\PageForCustomPostType\Integration\AdvancedCustomFields;

add_action('acf/include_location_rules', static function (int $acfMajorVersion): void {
if ($acfMajorVersion !== 5) {
return;
use n5s\PageForCustomPostType\Integration\IntegrationInterface;

/**
* Advanced Custom Fields integration composite.
*
* Registers a custom location type that exposes `<cpt>_page` values on the
* `page_type` rule, so field groups can target PFCPT-bound pages.
*/
final class AdvancedCustomFields implements IntegrationInterface
{
public function isSupported(): bool
{
return \function_exists('acf_register_location_type');
}

public function registerHooks(): void
{
add_action('acf/include_location_rules', [$this, 'registerLocationRules']);
}

require_once __DIR__ . '/LocationPageType.php';
public function registerLocationRules(int $acfFieldApiVersion): void
{
if ($acfFieldApiVersion !== 5) {
return;
}

$store = acf_get_store('location-types');
$locationType = new LocationPageType();
$store->set($locationType->name, $locationType);
});
$store = acf_get_store('location-types');
$store->remove('page_type');
acf_register_location_type(LocationPageType::class);
}
}
2 changes: 2 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use n5s\PageForCustomPostType\Core\RewriteManager;
use n5s\PageForCustomPostType\Frontend\Handler;
use n5s\PageForCustomPostType\Frontend\QueryFilter;
use n5s\PageForCustomPostType\Integration\AdvancedCustomFields;
use n5s\PageForCustomPostType\Integration\Autodescription;
use n5s\PageForCustomPostType\Integration\IntegrationInterface;
use n5s\PageForCustomPostType\Integration\Polylang;
Expand Down Expand Up @@ -184,6 +185,7 @@ public function onTemplateRedirect(): void
public function getIntegrations(): array
{
return [
AdvancedCustomFields\AdvancedCustomFields::class,
Polylang\Polylang::class,
WordPressSeo\WordPressSeo::class,
Wpml\Wpml::class,
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use n5s\PageForCustomPostType\Container;
use n5s\PageForCustomPostType\Core\Api;
use n5s\PageForCustomPostType\Core\RewriteManager;
use n5s\PageForCustomPostType\Integration\AdvancedCustomFields\AdvancedCustomFields;
use n5s\PageForCustomPostType\Integration\IntegrationInterface;
use n5s\PageForCustomPostType\Plugin;
use n5s\PageForCustomPostType\Tests\Fixtures\TestCase;
Expand Down Expand Up @@ -62,6 +63,7 @@ public function testGetIntegrationsReturnsArrayOfIntegrationClassStrings(): void

$this->assertIsArray($integrations);
$this->assertNotEmpty($integrations);
$this->assertContains(AdvancedCustomFields::class, $integrations);

foreach ($integrations as $integration) {
$this->assertIsString($integration);
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use n5s\PageForCustomPostType\Container;
use n5s\PageForCustomPostType\Core\Api;
use n5s\PageForCustomPostType\Core\RewriteManager;
use n5s\PageForCustomPostType\Integration\AdvancedCustomFields\AdvancedCustomFields;
use n5s\PageForCustomPostType\Tests\Fixtures\TestCase;

class ContainerTest extends TestCase
Expand All @@ -27,6 +28,13 @@ public function testGetReturnsCorrectTypeForApi(): void
$this->assertInstanceOf(Api::class, $service);
}

public function testGetReturnsCorrectTypeForAdvancedCustomFieldsIntegration(): void
{
$service = $this->container->get(AdvancedCustomFields::class);

$this->assertInstanceOf(AdvancedCustomFields::class, $service);
}

public function testGetReturnsSameInstanceOnRepeatedCalls(): void
{
$first = $this->container->get(Api::class);
Expand All @@ -39,6 +47,7 @@ public function testHasReturnsTrueForKnownServices(): void
{
$this->assertTrue($this->container->has(Api::class));
$this->assertTrue($this->container->has(RewriteManager::class));
$this->assertTrue($this->container->has(AdvancedCustomFields::class));
}

public function testHasReturnsFalseForUnknownServices(): void
Expand Down
Loading