diff --git a/lib/Listener/FileCreatedFromTemplateListener.php b/lib/Listener/FileCreatedFromTemplateListener.php index 8553a20b8a..c5fd304f76 100644 --- a/lib/Listener/FileCreatedFromTemplateListener.php +++ b/lib/Listener/FileCreatedFromTemplateListener.php @@ -54,18 +54,18 @@ public function handle(Event $event): void { return; } - if ($this->templateManager->isSupportedTemplateSource($templateFile->getExtension())) { - // Only use TemplateSource if supported filetype - $this->templateManager->setTemplateSource($event->getTarget()->getId(), $templateFile->getId()); - } - if ($this->capabilitiesService->hasFormFilling()) { try { - $filledTemplate = $this->templateFieldService->fillFields($templateFile, $event->getTemplateFields()); + $filledTemplate = $this->templateFieldService->fillFields($templateFile, $event->getTemplateFields(), null, event->getTarget()->getExtension()); $event->getTarget()->putContent($filledTemplate); } catch (\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); } + } else { + if ($this->templateManager->isSupportedTemplateSource($templateFile->getExtension())) { + // Only use TemplateSource if supported filetype + $this->templateManager->setTemplateSource($event->getTarget()->getId(), $templateFile->getId()); + } } // Avoid having the mimetype of the source file set diff --git a/lib/Service/TemplateFieldService.php b/lib/Service/TemplateFieldService.php index 917a23a6fc..d4fd1faf5f 100644 --- a/lib/Service/TemplateFieldService.php +++ b/lib/Service/TemplateFieldService.php @@ -177,7 +177,7 @@ public function fillFields(Node|int $file, array $fields = [], ?string $destinat $formFormat = [ 'name' => 'format', - 'contents' => $file->getExtension(), + 'contents' => $format === null ? $file->getExtension() : $format, ]; $form = RemoteOptionsService::getDefaultOptions(); @@ -191,13 +191,6 @@ public function fillFields(Node|int $file, array $fields = [], ?string $destinat $content = $response->getBody(); - if ($format !== null) { - $tmp = $this->tempManager->getTemporaryFile(); - file_put_contents($tmp, $content); - $fp = fopen($tmp, 'rb'); - $content = $this->remoteService->convertTo($file->getName(), $fp, $format); - } - if ($destination !== null) { $this->writeToDestination($destination, $content); }