mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 06:14:59 +00:00
move twig function in runtime
This commit is contained in:
@@ -11,8 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocStoreBundle\Templating;
|
||||
|
||||
use ChampsLibres\WopiLib\Contract\Service\Discovery\DiscoveryInterface;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
@@ -20,13 +18,6 @@ use Twig\TwigFunction;
|
||||
class WopiEditTwigExtension extends AbstractExtension
|
||||
{
|
||||
|
||||
private DiscoveryInterface $discovery;
|
||||
|
||||
public function __construct(DiscoveryInterface $discovery)
|
||||
{
|
||||
$this->discovery = $discovery;
|
||||
}
|
||||
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
@@ -40,22 +31,11 @@ class WopiEditTwigExtension extends AbstractExtension
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('chill_document_is_editable', [$this, 'isEditable']),
|
||||
new TwigFunction('chill_document_is_editable', [WopiEditTwigExtensionRuntime::class, 'isEditable'], [
|
||||
'needs_environment' => true,
|
||||
'is_safe' => ['html'],
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function isEditable(StoredObject $document): bool
|
||||
{
|
||||
$mime = $this->discovery->discoverMimeType($document->getType());
|
||||
|
||||
// TO CHECk is it better condition ?
|
||||
if (array_key_exists('default', $mime[0])
|
||||
&& $mime[0]['default'] === 'true'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//dump($document, $mime);
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user