Skip to content

Commit 6f42253

Browse files
author
Jaume Pujantell
committed
templates: better support cross-format templates
If form filling was used to create a file, do not add a template source. Otherwise Collabora Online creates the file again from the template. Use the format option in 'transform-document-structure' to avoid an intermediate save in the template format, which might not be supported as a save format. Signed-off-by: Jaume Pujantell <[email protected]>
1 parent f002ffc commit 6f42253

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

lib/Listener/FileCreatedFromTemplateListener.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ public function handle(Event $event): void {
5454
return;
5555
}
5656

57-
if ($this->templateManager->isSupportedTemplateSource($templateFile->getExtension())) {
58-
// Only use TemplateSource if supported filetype
59-
$this->templateManager->setTemplateSource($event->getTarget()->getId(), $templateFile->getId());
60-
}
61-
6257
if ($this->capabilitiesService->hasFormFilling()) {
6358
try {
64-
$filledTemplate = $this->templateFieldService->fillFields($templateFile, $event->getTemplateFields());
59+
$filledTemplate = $this->templateFieldService->fillFields($templateFile, $event->getTemplateFields(), null, event->getTarget()->getExtension());
6560
$event->getTarget()->putContent($filledTemplate);
6661
} catch (\Exception $e) {
6762
$this->logger->error($e->getMessage(), ['exception' => $e]);
6863
}
64+
} else {
65+
if ($this->templateManager->isSupportedTemplateSource($templateFile->getExtension())) {
66+
// Only use TemplateSource if supported filetype
67+
$this->templateManager->setTemplateSource($event->getTarget()->getId(), $templateFile->getId());
68+
}
6969
}
7070

7171
// Avoid having the mimetype of the source file set

lib/Service/TemplateFieldService.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function fillFields(Node|int $file, array $fields = [], ?string $destinat
177177

178178
$formFormat = [
179179
'name' => 'format',
180-
'contents' => $file->getExtension(),
180+
'contents' => $format === null ? $file->getExtension() : $format,
181181
];
182182

183183
$form = RemoteOptionsService::getDefaultOptions();
@@ -191,13 +191,6 @@ public function fillFields(Node|int $file, array $fields = [], ?string $destinat
191191

192192
$content = $response->getBody();
193193

194-
if ($format !== null) {
195-
$tmp = $this->tempManager->getTemporaryFile();
196-
file_put_contents($tmp, $content);
197-
$fp = fopen($tmp, 'rb');
198-
$content = $this->remoteService->convertTo($file->getName(), $fp, $format);
199-
}
200-
201194
if ($destination !== null) {
202195
$this->writeToDestination($destination, $content);
203196
}

0 commit comments

Comments
 (0)