mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
53 lines
1.4 KiB
PHP
53 lines
1.4 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\Environment;
|
|
use Twig\Extension\RuntimeExtensionInterface;
|
|
|
|
use function array_key_exists;
|
|
|
|
final class WopiEditTwigExtensionRuntime implements RuntimeExtensionInterface
|
|
{
|
|
private const TEMPLATE = '@ChillDocStore/Button/wopi_edit_document.html.twig';
|
|
|
|
private DiscoveryInterface $discovery;
|
|
|
|
public function __construct(DiscoveryInterface $discovery)
|
|
{
|
|
$this->discovery = $discovery;
|
|
}
|
|
|
|
public function isEditable(StoredObject $document): bool
|
|
{
|
|
$mime_type = $this->discovery->discoverMimeType($document->getType());
|
|
|
|
foreach ($mime_type as $item) {
|
|
if (array_key_exists('default', $item) && 'true' === $item['default']) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function renderEditButton(Environment $environment, StoredObject $document, ?array $options = null): string
|
|
{
|
|
return $environment->render(self::TEMPLATE, [
|
|
'document' => $document,
|
|
'options' => $options,
|
|
]);
|
|
}
|
|
}
|