2022-09-18 17:50:25 +02:00
|
|
|
<?php
|
2022-11-29 21:21:26 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2022-09-18 17:50:25 +02:00
|
|
|
|
|
|
|
|
namespace App\Twig;
|
|
|
|
|
|
|
|
|
|
use App\Services\Attachments\AttachmentURLGenerator;
|
2022-12-18 17:28:42 +01:00
|
|
|
use App\Services\Misc\FAIconGenerator;
|
2022-09-18 17:50:25 +02:00
|
|
|
use Twig\Extension\AbstractExtension;
|
|
|
|
|
use Twig\TwigFunction;
|
|
|
|
|
|
|
|
|
|
final class AttachmentExtension extends AbstractExtension
|
|
|
|
|
{
|
2023-06-11 14:15:46 +02:00
|
|
|
public function __construct(protected AttachmentURLGenerator $attachmentURLGenerator, protected FAIconGenerator $FAIconGenerator)
|
2022-09-18 17:50:25 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 22:59:31 +02:00
|
|
|
public function getFunctions(): array
|
2022-09-18 17:50:25 +02:00
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
/* Returns the URL to a thumbnail of the given attachment */
|
2023-06-11 14:15:46 +02:00
|
|
|
new TwigFunction('attachment_thumbnail', fn(\App\Entity\Attachments\Attachment $attachment, string $filter_name = 'thumbnail_sm'): ?string => $this->attachmentURLGenerator->getThumbnailURL($attachment, $filter_name)),
|
2022-09-18 17:50:25 +02:00
|
|
|
/* Returns the font awesome icon class which is representing the given file extension */
|
2023-06-11 14:15:46 +02:00
|
|
|
new TwigFunction('ext_to_fa_icon', fn(string $extension): string => $this->FAIconGenerator->fileExtensionToFAType($extension)),
|
2022-09-18 17:50:25 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|