mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
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;
|
|
|
|
class WopiEditTwigExtension extends AbstractExtension
|
|
{
|
|
|
|
private DiscoveryInterface $discovery;
|
|
|
|
public function __construct(DiscoveryInterface $discovery)
|
|
{
|
|
$this->discovery = $discovery;
|
|
}
|
|
|
|
public function getFilters(): array
|
|
{
|
|
return [
|
|
new TwigFilter('chill_document_edit_button', [WopiEditTwigExtensionRuntime::class, 'renderEditButton'], [
|
|
'needs_environment' => true,
|
|
'is_safe' => ['html'],
|
|
]),
|
|
];
|
|
}
|
|
|
|
public function getFunctions(): array
|
|
{
|
|
return [
|
|
new TwigFunction('chill_document_is_editable', [$this, 'isEditable']),
|
|
];
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |