From 4b2a92d0527443648bb730183e37e419b006dae9 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Wed, 18 Aug 2021 14:04:17 +0100 Subject: [PATCH] [UI][Attachment] Use Attachment methods to get the proper URL, rather than crafting it in a template --- plugins/ImageEncoder/ImageEncoder.php | 6 +++--- .../templates/imageEncoder/imageEncoderView.html.twig | 5 +++-- .../templates/videoEncoder/videoEncoderView.html.twig | 4 ++-- src/Entity/Attachment.php | 10 ++++++++-- templates/attachments/view.html.twig | 3 +-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/plugins/ImageEncoder/ImageEncoder.php b/plugins/ImageEncoder/ImageEncoder.php index 3b13979c1b..c799e753a7 100644 --- a/plugins/ImageEncoder/ImageEncoder.php +++ b/plugins/ImageEncoder/ImageEncoder.php @@ -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; } diff --git a/plugins/ImageEncoder/templates/imageEncoder/imageEncoderView.html.twig b/plugins/ImageEncoder/templates/imageEncoder/imageEncoderView.html.twig index 13bf76f3e1..5f4e469c9b 100644 --- a/plugins/ImageEncoder/templates/imageEncoder/imageEncoderView.html.twig +++ b/plugins/ImageEncoder/templates/imageEncoder/imageEncoderView.html.twig @@ -1,6 +1,7 @@
- {{ attachment.getFilename() }} + {{ attachment.getBestTitle(note) }}
{{ attachment.getBestTitle(note) }}
diff --git a/plugins/VideoEncoder/templates/videoEncoder/videoEncoderView.html.twig b/plugins/VideoEncoder/templates/videoEncoder/videoEncoderView.html.twig index 0525643ab9..e255dcf525 100644 --- a/plugins/VideoEncoder/templates/videoEncoder/videoEncoderView.html.twig +++ b/plugins/VideoEncoder/templates/videoEncoder/videoEncoderView.html.twig @@ -1,9 +1,9 @@
-
-
\ No newline at end of file + diff --git a/src/Entity/Attachment.php b/src/Entity/Attachment.php index 5e34118b29..272ee22d26 100644 --- a/src/Entity/Attachment.php +++ b/src/Entity/Attachment.php @@ -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 diff --git a/templates/attachments/view.html.twig b/templates/attachments/view.html.twig index 10e374b3df..c14138be4a 100644 --- a/templates/attachments/view.html.twig +++ b/templates/attachments/view.html.twig @@ -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 %}