Skip to content

Commit bc8fe7d

Browse files
committed
Add file_path var, tweak url parts
1 parent 4322fea commit bc8fe7d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Helper/Data.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function replaceImageUrlWithCustom(Image $image, string $imageUrl)
4848
}
4949

5050
$params = $image->getImageTransformationParameters();
51+
$params['file_path'] = $image->getFilePath();
5152

5253
if ($customType === CustomConfig::TYPE_PATTERN) {
5354
return $this->getCustomUrlFromPattern($imageUrl, $params);
@@ -67,9 +68,11 @@ public function getCustomUrlFromPattern(string $imageUrl, array $params): string
6768
$customUrl = $this->customConfig->getCustomPattern();
6869

6970
$urlParts = parse_url($imageUrl);
70-
$params = $params + $urlParts;
71+
foreach ($urlParts as $part => $value) {
72+
$params['url_' . $part] = $value;
73+
}
7174

72-
$params['path'] = ltrim($params['path'], '/');
75+
$params['path'] = ltrim($params['url_path'], '/');
7376
$params['base_url'] = $this->getBaseUrl();
7477
$params['base_url_media'] = $this->getMediaBaseUrl();
7578
$params['image_url'] = explode('?', $imageUrl)[0];

etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<field id="catalog_media_url_format_custom_type">pattern</field>
1717
</depends>
1818
<comment><![CDATA[Custom format to add dynamic parameters.<br/>
19-
<b>Available variables:</b> {{base_url}}, {{base_url_media}}, {{image_url}}, {{path}}, {{width}}, {{height}}, {{image_type}}, {{host}}, {{store}}. <br/><br/>
19+
<b>Available variables:</b> {{base_url}}, {{base_url_media}}, {{image_url}}, {{file_path}}, {{path}}, {{width}}, {{height}}, {{image_type}}, {{url_host}}, {{url_path}}, {{url_query}}, {{store}}. <br/><br/>
2020
<b>Filters:</b> {{path|urlencode}}, {{path|rawurlencode}}, {{path|base64}}<br/>
2121
<b>Example:</b> {{base_url}}{{path}}?w={{width}}&h={{height}}]]></comment>
2222
</field>

0 commit comments

Comments
 (0)