Skip to content

Commit 47905e9

Browse files
committed
fix: Make template file creator registration compatible with 28/29
Signed-off-by: Julius Knorr <[email protected]>
1 parent fd23e8e commit 47905e9

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/AppInfo/Application.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
use OCP\AppFramework\Bootstrap\IBootContext;
2121
use OCP\AppFramework\Bootstrap\IBootstrap;
2222
use OCP\AppFramework\Bootstrap\IRegistrationContext;
23+
use OCP\Files\Template\ITemplateManager;
2324
use OCP\Files\Template\RegisterTemplateCreatorEvent;
25+
use OCP\IL10N;
2426
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
27+
use OCP\Util;
2528

2629
/**
2730
* @psalm-suppress UndefinedClass
@@ -44,6 +47,13 @@ public function register(IRegistrationContext $context): void {
4447
}
4548

4649
public function boot(IBootContext $context): void {
47-
50+
[$major] = Util::getVersion();
51+
if ($major < 30) {
52+
$context->injectFn(function (ITemplateManager $templateManager, IL10N $l10n) use ($major) {
53+
$templateManager->registerTemplateFileCreator(function () use ($l10n) {
54+
return RegisterTemplateCreatorListener::getTemplateFileCreator($l10n);
55+
});
56+
});
57+
}
4858
}
4959
}

lib/Listener/RegisterTemplateCreatorListener.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ public function handle(Event $event): void {
3232

3333

3434
$event->getTemplateManager()->registerTemplateFileCreator(function () {
35-
$whiteboard = new TemplateFileCreator(Application::APP_ID, $this->l10n->t('New whiteboard'), '.whiteboard');
36-
$whiteboard->addMimetype('application/vnd.excalidraw+json');
37-
$whiteboard->setIconSvgInline(file_get_contents(__DIR__ . '/../../img/app-filetype.svg'));
38-
$whiteboard->setActionLabel($this->l10n->t('Create new whiteboard'));
39-
return $whiteboard;
35+
return self::getTemplateFileCreator($this->l10n);
4036
});
4137
}
38+
39+
public static function getTemplateFileCreator(IL10N $l10n): TemplateFileCreator {
40+
$whiteboard = new TemplateFileCreator(Application::APP_ID, $l10n->t('New whiteboard'), '.whiteboard');
41+
$whiteboard->addMimetype('application/vnd.excalidraw+json');
42+
$whiteboard->setIconSvgInline(file_get_contents(__DIR__ . '/../../img/app-filetype.svg'));
43+
$whiteboard->setActionLabel($l10n->t('Create new whiteboard'));
44+
return $whiteboard;
45+
}
4246
}

0 commit comments

Comments
 (0)