Skip to content

Commit fbcdc64

Browse files
Merge pull request #543 from Smartling/WP-911
add support for ACF `relation` field groups (WP-911)
2 parents 0d2c985 + e8a8931 commit fbcdc64

File tree

5 files changed

+52
-12
lines changed

5 files changed

+52
-12
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "smartling/wordpress-connector",
33
"license": "GPL-2.0-or-later",
4-
"version": "3.9.10",
4+
"version": "3.9.11",
55
"description": "",
66
"type": "wordpress-plugin",
77
"repositories": [

inc/Smartling/Services/ContentRelationsDiscoveryService.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,13 @@ public function getReferencesFromAcf(GutenbergBlock $block): array
711711
AcfDynamicSupport::REFERENCED_TYPE_POST,
712712
], true)) {
713713
$referencedValue = $block->getAttributes()['data'][substr($attribute, 1)] ?? null;
714-
if (is_numeric($referencedValue)) {
714+
if (is_array($referencedValue)) {
715+
foreach ($referencedValue as $innerReferencedValue) {
716+
if (is_numeric($innerReferencedValue)) {
717+
$result[] = (int)$innerReferencedValue;
718+
}
719+
}
720+
} elseif (is_numeric($referencedValue)) {
715721
$result[] = (int)$referencedValue;
716722
}
717723
}

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: translation, localization, localisation, translate, multilingual, smartlin
44
Requires at least: 5.5
55
Tested up to: 6.4.1
66
Requires PHP: 8.0
7-
Stable tag: 3.9.10
7+
Stable tag: 3.9.11
88
License: GPLv2 or later
99

1010
Translate content in WordPress quickly and seamlessly with Smartling, the industry-leading Translation Management System.
@@ -62,6 +62,9 @@ Additional information on the Smartling Connector for WordPress can be found [he
6262
3. Track translation status within WordPress from the Submissions Board. View overall progress of submitted translation requests as well as resend updated content.
6363

6464
== Changelog ==
65+
= 3.9.11 =
66+
* Added related content detection for ACF field groups with group type `relation`
67+
6568
= 3.9.10 =
6669
* Added logging of registered post types
6770

smartling-connector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Plugin Name: Smartling Connector
1212
* Plugin URI: https://www.smartling.com/products/automate/integrations/wordpress/
1313
* Description: Integrate your WordPress site with Smartling to upload your content and download translations.
14-
* Version: 3.9.10
14+
* Version: 3.9.11
1515
* Author: Smartling
1616
* Author URI: https://www.smartling.com
1717
* License: GPL-2.0+

tests/Services/ContentRelationDiscoveryServiceTest.php renamed to tests/Services/ContentRelationsDiscoveryServiceTest.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function apply_filters($a, ...$b) {
6767
use Smartling\Tuner\MediaAttachmentRulesManager;
6868
use Smartling\Vendor\Smartling\AuditLog\Params\CreateRecordParameters;
6969

70-
class ContentRelationDiscoveryServiceTest extends TestCase
70+
class ContentRelationsDiscoveryServiceTest extends TestCase
7171
{
7272
private ?\Exception $exception = null;
7373
protected function setUp(): void
@@ -750,19 +750,28 @@ public function testAcfReferencesDetected() {
750750
$irrelevantKey = 'field_5d5db4597e812';
751751

752752
$acfDynamicSupport = $this->createMock(AcfDynamicSupport::class);
753-
$acfDynamicSupport->expects($this->exactly(2))->method('getReferencedTypeByKey')
754-
->withConsecutive([$attachmentKey], [$irrelevantKey])
755-
->willReturnOnConsecutiveCalls(AcfDynamicSupport::REFERENCED_TYPE_MEDIA, AcfDynamicSupport::REFERENCED_TYPE_NONE);
753+
$matcher = $this->exactly(2);
754+
$acfDynamicSupport->expects($matcher)->method('getReferencedTypeByKey')
755+
->willReturnCallback(function ($key) use ($attachmentKey, $irrelevantKey, $matcher) {
756+
switch ($matcher->getInvocationCount()) {
757+
case 1:
758+
$this->assertEquals($attachmentKey, $key);
759+
760+
return AcfDynamicSupport::REFERENCED_TYPE_MEDIA;
761+
case 2:
762+
$this->assertEquals($irrelevantKey, $key);
763+
764+
return AcfDynamicSupport::REFERENCED_TYPE_NONE;
765+
}
766+
$this->fail('Expected two calls');
767+
});
756768

757769
$x = $this->getContentRelationDiscoveryService(
758770
$this->createMock(ApiWrapper::class),
759771
$this->createMock(ContentHelper::class),
760772
$this->createMock(SettingsManager::class),
761773
$this->createMock(SubmissionManager::class),
762-
null,
763-
null,
764-
null,
765-
$acfDynamicSupport
774+
acfDynamicSupport: $acfDynamicSupport,
766775
);
767776

768777
$this->assertEquals([$attachmentId], $x->getReferencesFromAcf(new GutenbergBlock('acf/gallery-carousel', [
@@ -777,6 +786,28 @@ public function testAcfReferencesDetected() {
777786
], [], '', [])));
778787
}
779788

789+
public function testAcfReferencesArraysDetected() {
790+
$acfDynamicSupport = $this->createMock(AcfDynamicSupport::class);
791+
$acfDynamicSupport->expects($this->once())->method('getReferencedTypeByKey')
792+
->willReturn(AcfDynamicSupport::REFERENCED_TYPE_POST);
793+
794+
$x = $this->getContentRelationDiscoveryService(
795+
$this->createMock(ApiWrapper::class),
796+
$this->createMock(ContentHelper::class),
797+
$this->createMock(SettingsManager::class),
798+
$this->createMock(SubmissionManager::class),
799+
acfDynamicSupport: $acfDynamicSupport,
800+
);
801+
802+
$this->assertEquals([22892, 22893], $x->getReferencesFromAcf(new GutenbergBlock('acf/gallery-carousel', [
803+
'name' => 'acf/testimonial-slider',
804+
'data' => [
805+
'testimonials_slider' => ["22892", "22893"],
806+
'_testimonials_slider' => 'field_66c32d42be1aa',
807+
]
808+
], [], '', [])));
809+
}
810+
780811
public function testGetRelations()
781812
{
782813
$contentType = 'post';

0 commit comments

Comments
 (0)