Skip to content

Commit 00279db

Browse files
Merge pull request #568 from Smartling/WP-945-icon-grid-widgets
add Unlimited Elements Listing Grid widget support, allow string id in icons (WP-945)
2 parents 0dd1346 + bf18054 commit 00279db

7 files changed

Lines changed: 223 additions & 4 deletions

File tree

inc/Smartling/ContentTypes/Elementor/ElementAbstract.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ public function getId(): string
4343
protected function getIntSettingByKey(string $key, array $settings): ?int
4444
{
4545
$setting = $this->getSettingByKey($key, $settings);
46+
if (is_int($setting)) {
47+
return $setting;
48+
}
49+
if (is_string($setting)) {
50+
return ctype_digit($setting) ? (int)$setting : null;
51+
}
4652

47-
return is_int($setting) ? $setting : null;
53+
return null;
4854
}
4955

5056
protected function getSettingByKey(string $key, array $settings): mixed
@@ -165,6 +171,9 @@ public function getDynamicTagsManager(): ?Manager
165171
if (class_exists(Manager::class)) {
166172
return new Manager();
167173
}
174+
if (!defined('WP_PLUGIN_DIR')) {
175+
return null;
176+
}
168177
$managerPath = WP_PLUGIN_DIR . '/elementor/core/dynamic-tags/manager.php';
169178
if (file_exists($managerPath)) {
170179
try {

inc/Smartling/ContentTypes/Elementor/Elements/UcAddonLogoMarquee.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public function getRelated(): RelatedContentInfo
2121
continue;
2222
}
2323
$key = "uc_items/$index/image/id";
24-
$id = $this->getSettingByKey($key, $this->settings);
25-
if (is_numeric($id)) {
24+
$id = $this->getIntSettingByKey($key, $this->settings);
25+
if ($id !== null) {
2626
$return->addContent(new Content((int)$id, ContentTypeHelper::POST_TYPE_ATTACHMENT), $this->id, "settings/$key");
2727
}
2828
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Smartling\ContentTypes\Elementor\Elements;
4+
5+
use Smartling\ContentTypes\ContentTypeHelper;
6+
use Smartling\Helpers\LoggerSafeTrait;
7+
use Smartling\Models\Content;
8+
use Smartling\Models\RelatedContentInfo;
9+
10+
class UcAddonUeListingGrid extends Unknown
11+
{
12+
use LoggerSafeTrait;
13+
14+
public function getType(): string
15+
{
16+
return 'ucaddon_ue_listing_grid';
17+
}
18+
19+
public function getRelated(): RelatedContentInfo
20+
{
21+
$return = parent::getRelated();
22+
$key = 'listing_template_templateid';
23+
$id = $this->getIntSettingByKey($key, $this->settings);
24+
if ($id !== null) {
25+
$return->addContent(new Content($id, ContentTypeHelper::CONTENT_TYPE_UNKNOWN), $this->id, "settings/$key");
26+
}
27+
28+
return $return;
29+
}
30+
31+
public function getTranslatableStrings(): array
32+
{
33+
return [$this->getId() => $this->getTranslatableStringsByKeys([
34+
'no_posts_found',
35+
])];
36+
}
37+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Smartling\ContentTypes\Elementor;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Smartling\ContentTypes\Elementor\Elements\Unknown;
7+
8+
class TestableElementAbstract extends Unknown
9+
{
10+
public function publicGetIntSettingByKey(string $key, array $settings): ?int
11+
{
12+
return $this->getIntSettingByKey($key, $settings);
13+
}
14+
}
15+
16+
class ElementAbstractTest extends TestCase
17+
{
18+
/**
19+
* @dataProvider settingsProvider
20+
*/
21+
public function testGetIntSettingByKey(string $key, array $settings, ?int $expected): void
22+
{
23+
$element = new TestableElementAbstract(['settings' => $settings]);
24+
$this->assertEquals($expected, $element->publicGetIntSettingByKey($key, $settings));
25+
}
26+
27+
public function settingsProvider(): array
28+
{
29+
return [
30+
['test', ['test' => 1], 1],
31+
['test', ['test' => 1.1], null],
32+
['test', ['test' => '1'], 1],
33+
['test', ['test' => '1.1'], null],
34+
['test', ['test' => 'non_integer'], null],
35+
['test', [], null],
36+
['test/test', ['test' => ['test' => 1]], 1],
37+
['test/test', ['test' => ['test' => '1']], 1],
38+
['test/test', ['test' => ['test' => 'non_integer']], null],
39+
['test/test', ['test' => []], null],
40+
['test/test', [], null],
41+
];
42+
}
43+
}

tests/Smartling/ContentTypes/ExternalContentElementorTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function extractElementorDataProvider(): array
5858
],
5959
[ContentTypeHelper::POST_TYPE_ATTACHMENT => [597]],
6060
],
61+
'icon' => [
62+
file_get_contents(__DIR__ . '/icon.json'),
63+
[],
64+
[ContentTypeHelper::POST_TYPE_ATTACHMENT => [1033]],
65+
],
6166
'background overlay' => [
6267
'[{"id":"b809dba","elType":"section","settings":{"background_background":"classic","background_image":{"url":"https:\/\/test.com\/wp-content\/uploads\/2023\/08\/gradient-circle-mask.png","id":15546,"size":"","alt":"Alt text in a background","source":"library"}},"elements":[]}]',
6368
['b809dba/background_image/alt' => 'Alt text in a background'],
@@ -251,7 +256,12 @@ public function extractElementorDataProvider(): array
251256
2680,
252257
]
253258
],
254-
]
259+
],
260+
'Unlimited Elements addon Listing Grid' => [
261+
file_get_contents(__DIR__ . '/ucaddon_ue_listing_grid.json'),
262+
['7bb0b763/no_posts_found' => 'No posts found'],
263+
[ContentTypeHelper::CONTENT_TYPE_UNKNOWN => [1531]],
264+
],
255265
];
256266
}
257267

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[
2+
{
3+
"id": "66bb7f43",
4+
"elType": "widget",
5+
"settings": {
6+
"selected_icon": {
7+
"value": {
8+
"url": "https:\/\/test.com\/wp-content\/uploads\/2025\/05\/play_icon.svg",
9+
"id": "1033"
10+
},
11+
"library": "svg"
12+
},
13+
"view": "stacked",
14+
"primary_color": "#4935BA",
15+
"size": {
16+
"unit": "px",
17+
"size": "26",
18+
"sizes": []
19+
},
20+
"size_mobile": {
21+
"unit": "px",
22+
"size": "19",
23+
"sizes": []
24+
},
25+
"icon_padding": {
26+
"unit": "px",
27+
"size": "20",
28+
"sizes": []
29+
},
30+
"_title": "Play Icon",
31+
"__dynamic__": []
32+
},
33+
"elements": [],
34+
"widgetType": "icon"
35+
}
36+
]
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
[
2+
{
3+
"id": "7bb0b763",
4+
"elType": "widget",
5+
"settings": {
6+
"listing_template_templateid": "1531",
7+
"no_posts_found": "No posts found",
8+
"remote_parent_enable": "true",
9+
"item_padding": {
10+
"unit": "px",
11+
"top": "",
12+
"right": "",
13+
"bottom": "",
14+
"left": "",
15+
"isLinked": true
16+
},
17+
"item_border_border": "none",
18+
"item_box_shadow_box_shadow_type": "yes",
19+
"item_box_shadow_box_shadow": {
20+
"horizontal": 5,
21+
"vertical": 0,
22+
"blur": 25,
23+
"spread": 0,
24+
"color": "rgba(0, 0, 0, 0.15)"
25+
},
26+
"item_border_hover_border": "none",
27+
"item_box_shadow_hover_box_shadow_type": "yes",
28+
"item_box_shadow_hover_box_shadow": {
29+
"horizontal": 5,
30+
"vertical": 0,
31+
"blur": 25,
32+
"spread": 0,
33+
"color": "rgba(0, 0, 0, 0.35)"
34+
},
35+
"item_border_active_border": "none",
36+
"listing_posts_posttype": [
37+
"blog",
38+
"case-study",
39+
"ebook",
40+
"report",
41+
"solution-guide",
42+
"video",
43+
"webinar-replay",
44+
"whitepaper"
45+
],
46+
"listing_posts_include_date_meta_format": "Ymd",
47+
"listing_posts_category": [],
48+
"listing_posts_offset": 1,
49+
"listing_posts_maxitems": "9",
50+
"listing_isajax": "true",
51+
"_element_width": "initial",
52+
"_element_custom_width": {
53+
"unit": "px",
54+
"size": 1200,
55+
"sizes": []
56+
},
57+
"__globals__": {
58+
"item_background_hover": "globals\/colors?id=accent",
59+
"item_background": "globals\/colors?id=accent"
60+
},
61+
"grid_gap": {
62+
"unit": "px",
63+
"size": 30,
64+
"sizes": [],
65+
"value": "20"
66+
},
67+
"listing_posts_includeby": [
68+
"meta"
69+
],
70+
"listing_posts_includeby_metakey": "featured_post_resources",
71+
"listing_posts_includeby_metavalue": "1",
72+
"listing_posts_category_relation": "OR",
73+
"listing_posts_terms_include_children": "",
74+
"listing_posts_posttype_current": "acf-ui-options-page",
75+
"__dynamic__": [],
76+
"listing_posts_includeby_metacompare": "!=",
77+
"_element_id": "all-resources",
78+
"listing_posts_queryid": "todos_posttypes_loop",
79+
"listing_filtering_group": "group2"
80+
},
81+
"elements": [],
82+
"widgetType": "ucaddon_ue_listing_grid"
83+
}
84+
]

0 commit comments

Comments
 (0)