Skip to content

Commit 0b0b370

Browse files
Merge pull request #607 from Smartling/WP-997-elementor-gallery
add elementor gallery support (WP-997)
2 parents 3e02f3d + 64a4140 commit 0b0b370

7 files changed

Lines changed: 174 additions & 3 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
name: bump-version
3+
description: Increase version number. Use this skill to update the version number before releasing a new version of the Smartling Connector. Usually, a release happens after a new feature is added.
4+
disable-model-invocation: true
5+
---
6+
7+
1. Examine changes in the current git branch compared to master.
8+
2. Decide if changes are minor, major or patch.
9+
3. Update the smartling-connector.php comment that starts with `Version:` with the new version number.
10+
4. Update the composer.json version with the new version number.
11+
5. Update the readme.txt `Stable tag:` with the new version number and add the release notes.

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": "5.3.2",
4+
"version": "5.3.3",
55
"description": "",
66
"type": "wordpress-plugin",
77
"repositories": [
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Smartling\ContentTypes\Elementor\Elements;
4+
5+
use Smartling\ContentTypes\ContentTypeHelper;
6+
use Smartling\ContentTypes\ExternalContentElementor;
7+
use Smartling\Models\Content;
8+
use Smartling\Models\RelatedContentInfo;
9+
use Smartling\Submissions\SubmissionEntity;
10+
11+
class Gallery extends Unknown {
12+
public function getType(): string
13+
{
14+
return 'gallery';
15+
}
16+
17+
public function getRelated(): RelatedContentInfo
18+
{
19+
$return = parent::getRelated();
20+
foreach ($this->settings['gallery'] ?? [] as $index => $listItem) {
21+
$key = "gallery/$index/id";
22+
$id = $this->getIntSettingByKey($key, $this->settings);
23+
if ($id !== null) {
24+
$return->addContent(new Content($id, ContentTypeHelper::POST_TYPE_ATTACHMENT), $this->id, "settings/$key");
25+
}
26+
}
27+
28+
return $return;
29+
}
30+
31+
public function getTranslatableStrings(): array
32+
{
33+
$return = [];
34+
foreach ($this->settings['galleries'] ?? [] as $gallery) {
35+
$id = $gallery['_id'] ?? null;
36+
if ($id !== null && array_key_exists('gallery_title', $gallery)) {
37+
$return['galleries/' . $id]['gallery_title'] = $gallery['gallery_title'];
38+
}
39+
}
40+
41+
return [$this->getId() => $return];
42+
}
43+
44+
public function setTargetContent(ExternalContentElementor $externalContentElementor, RelatedContentInfo $info, array $strings, SubmissionEntity $submission): static
45+
{
46+
foreach ($strings[$this->id] ?? [] as $array) {
47+
if (is_array($array)) {
48+
foreach ($array as $id => $values) {
49+
foreach ($this->settings['galleries'] ?? [] as $index => $gallery) {
50+
if (($gallery['_id'] ?? '') === $id) {
51+
foreach ($values as $property => $value) {
52+
$this->settings['galleries'][$index][$property] = $value;
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}
59+
$this->raw['settings'] = $this->settings;
60+
61+
return new static($this->raw);
62+
}
63+
}

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: translation, localization, multilingual, internationalization, smartling
44
Requires at least: 5.5
55
Tested up to: 6.9
66
Requires PHP: 8.0
7-
Stable tag: 5.3.2
7+
Stable tag: 5.3.3
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+
= 5.3.3 =
66+
* Added support for Elementor gallery widget
67+
6568
= 5.3.2 =
6669
* Added support for Elementor nested accordion widget
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: 5.3.2
14+
* Version: 5.3.3
1515
* Author: Smartling
1616
* Author URI: https://www.smartling.com
1717
* License: GPL-2.0+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace Smartling\ContentTypes\Elementor;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Smartling\ContentTypes\ContentTypeHelper;
7+
use Smartling\ContentTypes\Elementor\Elements\Gallery;
8+
use Smartling\ContentTypes\ExternalContentElementor;
9+
use Smartling\Models\Content;
10+
use Smartling\Models\RelatedContentInfo;
11+
use Smartling\Submissions\SubmissionEntity;
12+
13+
class GalleryTest extends TestCase
14+
{
15+
private function makeWidget(array $settings = []): Gallery
16+
{
17+
return new Gallery([
18+
'id' => '14d5abc',
19+
'elType' => 'widget',
20+
'widgetType' => 'gallery',
21+
'settings' => $settings,
22+
'elements' => [],
23+
]);
24+
}
25+
26+
public function testRelated(): void
27+
{
28+
$imageSourceId = 21162;
29+
$imageTargetId = 31162;
30+
31+
$externalContentElementor = $this->createMock(ExternalContentElementor::class);
32+
$externalContentElementor->method('getTargetId')
33+
->with(0, $imageSourceId, 0, ContentTypeHelper::POST_TYPE_ATTACHMENT)->willReturn($imageTargetId);
34+
35+
$this->assertEquals(
36+
$imageTargetId,
37+
$this->makeWidget(['gallery' => [
38+
['id' => 21161, 'url' => 'https://example.com/1.webp'],
39+
['id' => $imageSourceId, 'url' => 'https://example.com/2.webp'],
40+
['id' => 21163, 'url' => 'https://example.com/3.webp'],
41+
]])
42+
->setRelations(
43+
new Content($imageSourceId, ContentTypeHelper::POST_TYPE_ATTACHMENT),
44+
$externalContentElementor,
45+
'settings/gallery/1/id',
46+
$this->createMock(SubmissionEntity::class),
47+
)->toArray()['settings']['gallery'][1]['id'],
48+
);
49+
}
50+
51+
public function testGetTranslatableStrings(): void
52+
{
53+
$strings = $this->makeWidget(['galleries' => [
54+
['gallery_title' => 'New Gallery', '_id' => '04c68ec'],
55+
['gallery_title' => 'Second Gallery', '_id' => 'ab12345'],
56+
]])->getTranslatableStrings();
57+
58+
$this->assertEquals('New Gallery', $strings['14d5abc']['galleries/04c68ec']['gallery_title']);
59+
$this->assertEquals('Second Gallery', $strings['14d5abc']['galleries/ab12345']['gallery_title']);
60+
}
61+
62+
public function testSetTargetContent(): void
63+
{
64+
$result = $this->makeWidget(['galleries' => [
65+
['gallery_title' => 'New Gallery', '_id' => '04c68ec'],
66+
['gallery_title' => 'Second Gallery', '_id' => 'ab12345'],
67+
]])->setTargetContent(
68+
$this->createMock(ExternalContentElementor::class),
69+
new RelatedContentInfo([]),
70+
[
71+
'14d5abc' => [
72+
'galleries' => [
73+
'04c68ec' => ['gallery_title' => 'Translated Gallery'],
74+
'ab12345' => ['gallery_title' => 'Translated Second'],
75+
],
76+
],
77+
],
78+
$this->createMock(SubmissionEntity::class),
79+
)->toArray();
80+
81+
$this->assertEquals('Translated Gallery', $result['settings']['galleries'][0]['gallery_title']);
82+
$this->assertEquals('Translated Second', $result['settings']['galleries'][1]['gallery_title']);
83+
}
84+
}

tests/Smartling/ContentTypes/ExternalContentElementorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,16 @@ public function extractElementorDataProvider(): array
323323
['abc123/text' => 'Click Me'],
324324
[ContentTypeHelper::POST_TYPE_ATTACHMENT => [789]],
325325
],
326+
'gallery widget' => [
327+
'[{"id":"14d5abc","elType":"widget","settings":{"gallery":[{"id":21161,"url":"https://example.com/1.webp"},{"id":21162,"url":"https://example.com/2.webp"}],"galleries":[{"gallery_title":"New Gallery","_id":"04c68ec"}]},"elements":[],"widgetType":"gallery"}]',
328+
['14d5abc/galleries/04c68ec/gallery_title' => 'New Gallery'],
329+
[ContentTypeHelper::POST_TYPE_ATTACHMENT => [21161, 21162]],
330+
],
331+
'nested accordion with svg icons' => [
332+
'[{"id":"cf8c5a0","elType":"widget","settings":{"accordion_item_title_icon":{"value":{"url":"https://example.com/plus.svg","id":329},"library":"svg"},"accordion_item_title_icon_active":{"value":{"url":"https://example.com/minus.svg","id":330},"library":"svg"}},"elements":[],"widgetType":"nested-accordion"}]',
333+
[],
334+
[ContentTypeHelper::POST_TYPE_ATTACHMENT => [329, 330]],
335+
],
326336
'dynamic content in elements' => [
327337
file_get_contents(__DIR__ . '/wp-975.json'),
328338
[],

0 commit comments

Comments
 (0)