From 018fff2c3f35ad29ae64b66f45e9a8d6a4b9556e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 11 Jul 2023 12:48:13 +0200 Subject: [PATCH] fix: Create empty files from template if available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Listener/FileCreatedFromTemplateListener.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Listener/FileCreatedFromTemplateListener.php b/lib/Listener/FileCreatedFromTemplateListener.php index 04d58bb607..731a6d5da5 100644 --- a/lib/Listener/FileCreatedFromTemplateListener.php +++ b/lib/Listener/FileCreatedFromTemplateListener.php @@ -52,6 +52,13 @@ public function handle(Event $event): void { // Empty template if ($templateFile === null) { $event->getTarget()->putContent($this->templateManager->getEmptyFileContent($event->getTarget()->getExtension())); + $templateType = $this->templateManager->getTemplateTypeForExtension($event->getTarget()->getExtension()); + $emptyTemplates = $this->templateManager->getEmpty($templateType); + $emptyTemplate = array_shift($emptyTemplates); + if ($emptyTemplate && $this->templateManager->isSupportedTemplateSource($emptyTemplate->getExtension())) { + // Only use TemplateSource if supported filetype + $this->templateManager->setTemplateSource($event->getTarget()->getId(), $emptyTemplate->getId()); + } return; }