[UI][Attachment] Use Attachment methods to get the proper URL, rather than crafting it in a template

This commit is contained in:
Hugo Sales 2021-08-18 14:04:17 +01:00
parent 9c533a54a7
commit 7320c6834f
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
5 changed files with 17 additions and 11 deletions

View File

@ -143,9 +143,9 @@ class ImageEncoder extends Plugin
public function onViewAttachmentImage(array $vars, array &$res): bool
{
$res[] = Formatting::twigRenderFile('imageEncoder/imageEncoderView.html.twig',
['attachment' => $vars['attachment'],
'thumbnail_parameters' => $vars['thumbnail_parameters'],
'note' => $vars['note'],
[
'attachment' => $vars['attachment'],
'note' => $vars['note'],
]);
return Event::stop;
}

View File

@ -1,6 +1,7 @@
<figure>
<img class="u-photo" src="{{ path('attachment_thumbnail', thumbnail_parameters) }}"
alt="{{ attachment.getFilename() }}">
<img class="u-photo"
alt="{{ attachment.getBestTitle(note) }}"
src="{{ attachment.getThumbnailUrl() }}">
<figcaption><a
href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getBestTitle(note) }}</a>
</figcaption>

View File

@ -1,9 +1,9 @@
<div>
<figure>
<video class="u-video" src="{{ path('attachment_view', {'id': attachment.getId()}) }}" controls poster="{{ path('attachment_thumbnail', thumbnail_parameters) }}">
<video class="u-video" src="{{ attachment.getUrl() }}" controls poster="{{ attachment.getThumbnailUrl()}}">
</video>
<figcaption><a
href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getBestTitle(note) }}</a>
</figcaption>
</figure>
</div>
</div>

View File

@ -21,6 +21,7 @@
namespace App\Entity;
use App\Core\Router\Router;
use App\Core\DB\DB;
use App\Core\Entity;
use App\Core\GSFile;
@ -315,9 +316,14 @@ class Attachment extends Entity
return is_null($filename) ? null : Common::config('attachments', 'dir') . $filename;
}
public function getAttachmentUrl()
public function getUrl()
{
return Router::url('attachment_thumbnail', ['id' => $this->getAttachmentId(), 'w' => Common::config('attachment', 'width'), 'h' => Common::config('attachment', 'height')]);
return Router::url('attachment_view', ['id' => $this->getId()]);
}
public function getThumbnailUrl()
{
return Router::url('attachment_thumbnail', ['id' => $this->getId(), 'w' => Common::config('thumbnail', 'width'), 'h' => Common::config('thumbnail', 'height')]);;
}
public static function schemaDef(): array

View File

@ -1,6 +1,5 @@
{% set thumbnail_parameters = {'id': attachment.getId(), 'w': config('thumbnail','width'), 'h': config('thumbnail','height')} %}
{% set handled = false %}
{% for block in handle_event('ViewAttachment' ~ attachment.getMimetypeMajor() | capitalize , {'attachment': attachment, 'thumbnail_parameters': thumbnail_parameters, 'note': note}) %}
{% for block in handle_event('ViewAttachment' ~ attachment.getMimetypeMajor() | capitalize , {'attachment': attachment, 'note': note}) %}
{% set handled = true %}
{{ block | raw }}
{% endfor %}