Feature: allow to convert to PDF from Chill and group action button on document

BREAKING CHANGE: avoid using the macro for download button. To keep the UI clean, use always the new "group of action buttons".
This commit is contained in:
2023-01-31 16:30:19 +00:00
parent e5bc74d11d
commit 9f5b11e6cc
30 changed files with 770 additions and 161 deletions

View File

@@ -13,6 +13,8 @@ namespace Chill\DocStoreBundle\Templating;
use ChampsLibres\WopiLib\Contract\Service\Discovery\DiscoveryInterface;
use Chill\DocStoreBundle\Entity\StoredObject;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Twig\Environment;
use Twig\Extension\RuntimeExtensionInterface;
@@ -112,20 +114,53 @@ final class WopiEditTwigExtensionRuntime implements RuntimeExtensionInterface
'application/pdf',
];
private const DEFAULT_OPTIONS_TEMPLATE_BUTTON_GROUP = [
'small' => false,
];
private const TEMPLATE = '@ChillDocStore/Button/wopi_edit_document.html.twig';
private const TEMPLATE_BUTTON_GROUP = '@ChillDocStore/Button/button_group.html.twig';
private DiscoveryInterface $discovery;
public function __construct(DiscoveryInterface $discovery)
private NormalizerInterface $normalizer;
public function __construct(DiscoveryInterface $discovery, NormalizerInterface $normalizer)
{
$this->discovery = $discovery;
$this->normalizer = $normalizer;
}
/**
* return true if the document is editable.
*
* **NOTE**: as the Vue button does have similar test, this is not required if in use with
* the dedicated Vue component (GroupDownloadButton.vue, WopiEditButton.vue)
*/
public function isEditable(StoredObject $document): bool
{
return in_array($document->getType(), self::SUPPORTED_MIMES, true);
}
/**
* @param array{small: boolean} $options
*
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function renderButtonGroup(Environment $environment, StoredObject $document, ?string $title = null, bool $canEdit = true, array $options = []): string
{
return $environment->render(self::TEMPLATE_BUTTON_GROUP, [
'document' => $document,
'document_json' => $this->normalizer->normalize($document, 'json', [AbstractNormalizer::GROUPS => ['read']]),
'title' => $title,
'can_edit' => $canEdit,
'options' => array_merge($options, self::DEFAULT_OPTIONS_TEMPLATE_BUTTON_GROUP),
]);
}
public function renderEditButton(Environment $environment, StoredObject $document, ?array $options = null): string
{
return $environment->render(self::TEMPLATE, [