false, ]; private const TEMPLATE = '@ChillDocStore/Button/wopi_edit_document.html.twig'; private const TEMPLATE_BUTTON_GROUP = '@ChillDocStore/Button/button_group.html.twig'; public function __construct( private DiscoveryInterface $discovery, private NormalizerInterface $normalizer, private JWTDavTokenProviderInterface $davTokenProvider, private UrlGeneratorInterface $urlGenerator, private Security $security, ) {} /** * 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: bool} $options * * @throws \Twig\Error\LoaderError * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError */ public function renderButtonGroup(Environment $environment, StoredObject $document, ?string $title = null, bool $showEditButtons = true, array $options = []): string { $canEdit = $this->security->isGranted(StoredObjectRoleEnum::EDIT->value, $document) && $showEditButtons; $accessToken = $this->davTokenProvider->createToken( $document, $canEdit ? StoredObjectRoleEnum::EDIT : StoredObjectRoleEnum::SEE ); 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' => [...self::DEFAULT_OPTIONS_TEMPLATE_BUTTON_GROUP, ...$options], 'dav_link' => $this->urlGenerator->generate( 'chill_docstore_dav_document_get', [ 'uuid' => $document->getUuid(), 'access_token' => $accessToken, ], UrlGeneratorInterface::ABSOLUTE_URL, ), 'dav_link_expiration' => $this->davTokenProvider->getTokenExpiration($accessToken)->format('U'), ]); } public function renderDownloadButton(Environment $environment, StoredObject $storedObject, string $title = ''): string { return $environment->render( '@ChillDocStore/Button/button_download.html.twig', [ 'document_json' => $this->normalizer->normalize($storedObject, 'json', [AbstractNormalizer::GROUPS => ['read', StoredObjectNormalizer::DOWNLOAD_LINK_ONLY]]), 'title' => $title, ] ); } public function renderEditButton(Environment $environment, StoredObject $document, ?array $options = null): string { return $environment->render(self::TEMPLATE, [ 'document' => $document, 'options' => $options, ]); } }