Skip to content

Commit 63417d1

Browse files
author
roadiz-ci
committed
fix(hotspot): add size attributes to image (#169)
1 parent 3cf5ac9 commit 63417d1

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/Explorer/DocumentExplorerItem.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ public function toArray(): array
139139
$thumbnail80Url = $this->documentUrlGenerator->getUrl();
140140
$this->documentUrlGenerator->setOptions($previewOptions);
141141
$editImageUrl = $this->documentUrlGenerator->getUrl();
142+
$editImageWidth = $this->document->getImageWidth();
143+
$editImageHeight = $this->document->getImageHeight();
142144
}
143145

144146
$embedFinder = $this->embedFinderFactory?->createForPlatform(
@@ -169,6 +171,8 @@ public function toArray(): array
169171
'shortMimeType' => $this->document->getShortMimeType(),
170172
'thumbnail80' => $thumbnail80Url,
171173
'editImageUrl' => $editImageUrl,
174+
'editImageWidth' => $editImageWidth,
175+
'editImageHeight' => $editImageHeight,
172176
'originalHotspot' => $originalHotspot ?? null,
173177
];
174178
}

src/Form/DocumentEditType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
124124
'width' => 800,
125125
'height' => 800,
126126
])->getUrl(),
127+
'image-width' => $document->getImageWidth(),
128+
'image-height' => $document->getImageHeight(),
127129
],
128130
]);
129131
}

templates/widgets/documentAlignment.html.twig

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
{% set imagePath = widget_attributes|split('image-path="')[1]|split('"')[0] %}
1+
{% macro getWidgetAttribute(widget_attributes, attribute_name) %}
2+
{%- set pattern = attribute_name ~ '="' -%}
3+
{%- if pattern in widget_attributes -%}
4+
{{- widget_attributes|split(pattern)[1]|split('"')[0] -}}
5+
{%- endif -%}
6+
{% endmacro %}
7+
8+
{% set imagePath = _self.getWidgetAttribute(widget_attributes, 'image-path') %}
9+
{% set imageWidth = _self.getWidgetAttribute(widget_attributes, 'image-width') %}
10+
{% set imageHeight = _self.getWidgetAttribute(widget_attributes, 'image-height') %}
211

312
<document-alignment-widget class="document-alignment-widget" input-base-name="{{ form.vars.full_name }}">
413
<div class="document-alignment-widget__image-wrapper">
@@ -11,7 +20,13 @@
1120
</div>
1221
<div class="document-alignment-widget__hotspot"></div>
1322
</div>
14-
<img class="document-alignment-widget__image" src="{{ imagePath }}" alt=""/>
23+
<img
24+
class="document-alignment-widget__image"
25+
src="{{ imagePath }}"
26+
width="{{ imageWidth }}"
27+
height="{{ imageHeight }}"
28+
alt=""
29+
/>
1530
</div>
1631
<label class="document-alignment-widget__override">
1732
<input type="checkbox" class="rz-boolean-checkbox" data-on-text="I" data-off-text="O" />

0 commit comments

Comments
 (0)