Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Render/MediaRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function imageUrl(MediaInterface|string $media, $version, array $attr = [
}
}

public function mediaVersionUrl(?MediaVersionInterface $version): ?string
{
return $this->getFinalUrl($version);
}

/**
* @throws Exception
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Twig/Extension/RenderMediaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function getFilters(): array
new TwigFilter('sfs_media_render_picture', [$this->mediaRenderer, 'renderPicture'], ['is_safe' => ['html']]),
new TwigFilter('sfs_media_render', [$this->mediaRenderer, 'renderMediaOrArray'], ['is_safe' => ['html']]),
new TwigFilter('sfs_media_image_url', [$this->mediaRenderer, 'imageUrl']),
new TwigFilter('sfs_media_version_url', [$this->mediaRenderer, 'mediaVersionUrl']),
new TwigFilter('sfs_media_type_config', [$this, 'getMediaTypeConfig']),
];
}
Expand All @@ -44,6 +45,7 @@ public function getFunctions(): array
new TwigFunction('sfs_media_render_picture', [$this->mediaRenderer, 'renderPicture'], ['is_safe' => ['html']]),
new TwigFunction('sfs_media_render', [$this->mediaRenderer, 'renderMediaOrArray'], ['is_safe' => ['html']]),
new TwigFunction('sfs_media_image_url', [$this->mediaRenderer, 'imageUrl']),
new TwigFunction('sfs_media_version_url', [$this->mediaRenderer, 'mediaVersionUrl']),
new TwigFunction('sfs_media_type_config', [$this, 'getMediaTypeConfig']),
];
}
Expand Down
7 changes: 4 additions & 3 deletions templates/admin/media/_macros.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{%- endmacro -%}

{%- macro renderVersion(media, version, media_types) -%}
{% set versionUrl = version|sfs_media_version_url %}
<div class="text-small text-black-50 mb-1">
{% if media_types[media.type].name|default(null) %}
<span class="me-2">{{ media_types[media.type].name }}</span>
Expand All @@ -46,10 +47,10 @@
{% endfor %}">Automatically generated</abbr> at: {{ version.generatedAt|date_span('H:i:s d-m-Y') }}
{% endif %}
</span>
{# <a class="btn btn-link btn-sm" href="{{ version.publicUrl }}" download>
{# <a class="btn btn-link btn-sm" href="{{ versionUrl }}" download>
<i class="bi bi-download"></i>
</a> #}
<a class="btn btn-link btn-sm" href="{{ version.publicUrl }}" target="_blank">
<a class="btn btn-link btn-sm" href="{{ versionUrl }}" target="_blank">
<i class="bi bi-box-arrow-up-right"></i>
</a>
</div>
Expand Down Expand Up @@ -111,7 +112,7 @@
<strong>Directly using the URL</strong>
<a href="#" onclick="navigator.clipboard.writeText(document.querySelector('#media_version_url_{{ version.version }}').textContent); return false" title="Copy to clipboard"><i class="bi bi-copy"></i></a>
<br/>
<a href="{{ version.publicUrl }}" target="_blank" id="media_version_url_{{ version.version }}">{{ version.publicUrl }}</a>
<a href="{{ versionUrl }}" target="_blank" id="media_version_url_{{ version.version }}">{{ versionUrl }}</a>
</p>
</div>
</div>
Expand Down
9 changes: 5 additions & 4 deletions templates/forms/media_type_theme.html.twig
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{% trans_default_domain 'sfs_media_admin' %}

{% block media_version_upload_row %}
{% set mediaVersionPublicUrl = form.vars.value|sfs_media_version_url|default('') %}
{{ form_label(form) }}
<div data-drop-media-zone class="border border-3 rounded-3 bg-light mb-3 p-3" style="border-style: dashed !important;">
<div class="d-flex align-items justify-content-between flex-wrap">
<div class="d-flex align-items-center pe-3 col">
<div class="d-flex justify-content-center align-items-center rounded me-3 h-100 px-2" data-drop-media-zone-preview style="width: 125px;">
<i class="icon bi bi-image{{ (form.vars.value.publicUrl is empty) ? '' : ' d-none' }}"></i>
<img src="{{ form.vars.value.publicUrl|default('') }}" class="img-thumbnail preview-image{{ (form.vars.value.publicUrl is not empty and form.vars.value.isImageFile) ? '' : ' d-none' }}" alt="Image Preview" style="max-width: 120px; max-height: 120px;">
<video controls class="preview-video{{ (form.vars.value.publicUrl is not empty and form.vars.value.isVideoFile) ? '' : ' d-none' }}" style="max-width: 120px; max-height: 120px;">
<source src="{{ form.vars.value.publicUrl|default('') }}" type="">
<i class="icon bi bi-image{{ (mediaVersionPublicUrl is empty) ? '' : ' d-none' }}"></i>
<img src="{{ mediaVersionPublicUrl }}" class="img-thumbnail preview-image{{ (mediaVersionPublicUrl is not empty and form.vars.value.isImageFile) ? '' : ' d-none' }}" alt="Image Preview" style="max-width: 120px; max-height: 120px;">
<video controls class="preview-video{{ (mediaVersionPublicUrl is not empty and form.vars.value.isVideoFile) ? '' : ' d-none' }}" style="max-width: 120px; max-height: 120px;">
<source src="{{ mediaVersionPublicUrl }}" type="">
Your browser does not support the video tag.
</video>
</div>
Expand Down
Loading