mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-22 11:54:41 +02:00
Refactored TwigExtensions Part 2
This commit is contained in:
parent
b078389381
commit
a9e527ce2a
22 changed files with 168 additions and 124 deletions
30
src/Twig/AttachmentExtension.php
Normal file
30
src/Twig/AttachmentExtension.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Services\Attachments\AttachmentURLGenerator;
|
||||
use App\Services\FAIconGenerator;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
final class AttachmentExtension extends AbstractExtension
|
||||
{
|
||||
protected $attachmentURLGenerator;
|
||||
protected $FAIconGenerator;
|
||||
|
||||
public function __construct(AttachmentURLGenerator $attachmentURLGenerator, FAIconGenerator $FAIconGenerator)
|
||||
{
|
||||
$this->attachmentURLGenerator = $attachmentURLGenerator;
|
||||
$this->FAIconGenerator = $FAIconGenerator;
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
/* Returns the URL to a thumbnail of the given attachment */
|
||||
new TwigFunction('attachment_thumbnail', [$this->attachmentURLGenerator, 'getThumbnailURL']),
|
||||
/* Returns the font awesome icon class which is representing the given file extension */
|
||||
new TwigFunction('ext_to_fa_icon', [$this->FAIconGenerator, 'fileExtensionToFAType']),
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue