Skip to content

Commit 7a42b81

Browse files
committed
Add imgproxy custom source url setting
1 parent bc8fe7d commit 7a42b81

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

Helper/Data.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public function getImgProxyUrl(string $imageUrl, array $params)
118118
$path = $prefix . '/' . $path;
119119
}
120120
$sourceUrl = 'local:///' . $path;
121+
} elseif ($this->customConfig->getImgproxySourceType() === CustomConfig::IMGPROXY_CUSTOM_URL) {
122+
$proxyUrl = trim($this->customConfig->getImgproxySourceCustomUrl(), '/');
123+
$sourceUrl = $proxyUrl . '/' . $path;
121124
} else {
122125
$sourceUrl = $imageUrl;
123126
}

Model/Config/CustomConfig.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ class CustomConfig
2525

2626
public const XML_PATH_CATALOG_MEDIA_URL_FORMAT_CUSTOM_IMGPROXY_SOURCE_TYPE = 'web/url/catalog_media_url_format_custom_imgproxy_source_type';
2727
public const XML_PATH_CATALOG_MEDIA_URL_FORMAT_CUSTOM_IMGPROXY_SOURCE_PREFIX = 'web/url/catalog_media_url_format_custom_imgproxy_source_prefix';
28+
public const XML_PATH_CATALOG_MEDIA_URL_FORMAT_CUSTOM_IMGPROXY_SOURCE_CUSTOM_URL = 'web/url/catalog_media_url_format_custom_imgproxy_source_custom_url';
2829

2930
public const TYPE_DEFAULT = 'default';
3031
public const TYPE_PATTERN = 'pattern';
3132
public const TYPE_IMGPROXY = 'imgproxy';
3233

3334
public const IMGPROXY_URL = 'url';
35+
public const IMGPROXY_CUSTOM_URL = 'custom_url';
3436
public const IMGPROXY_LOCAL = 'local';
3537
public const IMGPROXY_S3 = 's3';
3638

@@ -108,6 +110,14 @@ public function getImgproxySourcePrefix($storeId = null): string
108110
) ?: '';
109111
}
110112

113+
public function getImgproxySourceCustomUrl($storeId = null): string
114+
{
115+
return $this->scopeConfig->getValue(
116+
self::XML_PATH_CATALOG_MEDIA_URL_FORMAT_CUSTOM_IMGPROXY_SOURCE_CUSTOM_URL,
117+
ScopeInterface::SCOPE_STORE,
118+
$storeId
119+
) ?: '';
120+
}
111121

112122
public function getImgproxyKey($storeId = null): string
113123
{

Model/Config/Source/ImgproxySourceType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function toOptionArray(): array
2727
'value' => CustomConfig::IMGPROXY_URL,
2828
'label' => __('URL: Proxy the default URL')
2929
],
30+
[
31+
'value' => CustomConfig::IMGPROXY_CUSTOM_URL,
32+
'label' => __('Custom URL: Proxy an url other than the default URL')
33+
],
3034
[
3135
'value' => CustomConfig::IMGPROXY_LOCAL,
3236
'label' => __('Local: Pass the local path')

Plugin/AssetImagePlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class AssetImagePlugin
99
{
10-
/** @var $helper */
10+
/** @var Data $helper */
1111
private $helper;
1212

1313
public function __construct(Data $helper)

etc/adminhtml/system.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@
6666
</depends>
6767
<comment><![CDATA[For s3, provide both the bucket and optional prefix.]]></comment>
6868
</field>
69+
<field id="catalog_media_url_format_custom_imgproxy_source_custom_url" translate="label comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="0">
70+
<label>Imgproxy Source Custom URL</label>
71+
<depends>
72+
<field id="catalog_media_url_format_custom_type">imgproxy</field>
73+
<field id="catalog_media_url_format_custom_imgproxy_source_type" separator=",">custom_url</field>
74+
</depends>
75+
<comment><![CDATA[Enter a custom URL to proxy.]]></comment>
76+
</field>
6977
</group>
7078
</section>
7179
</system>

0 commit comments

Comments
 (0)