mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
move twig function in runtime
This commit is contained in:
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocStoreBundle\Templating;
|
||||
|
||||
use ChampsLibres\WopiLib\Contract\Service\Discovery\DiscoveryInterface;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\RuntimeExtensionInterface;
|
||||
@@ -20,6 +21,13 @@ class WopiEditTwigExtensionRuntime implements RuntimeExtensionInterface
|
||||
|
||||
public const TEMPLATE = '@ChillDocStore/Button/wopi_edit_document.html.twig';
|
||||
|
||||
private DiscoveryInterface $discovery;
|
||||
|
||||
public function __construct(DiscoveryInterface $discovery)
|
||||
{
|
||||
$this->discovery = $discovery;
|
||||
}
|
||||
|
||||
public function renderEditButton(Environment $environment, StoredObject $document, ?Array $options = null): string
|
||||
{
|
||||
return $environment->render(self::TEMPLATE, [
|
||||
@@ -27,4 +35,21 @@ class WopiEditTwigExtensionRuntime implements RuntimeExtensionInterface
|
||||
'options' => $options
|
||||
]);
|
||||
}
|
||||
|
||||
public function isEditable(Environment $environment, StoredObject $document): bool
|
||||
{
|
||||
$mime_type = $this->discovery->discoverMimeType($document->getType());
|
||||
|
||||
if (empty($mime_type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (array_key_exists('default', $mime_type[0])
|
||||
&& $mime_type[0]['default'] === 'true'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user