Skip to content

Commit 2b61c7a

Browse files
authored
Merge pull request #2319 from nextcloud/enh/template-event
Move style loading to BeforeTemplateRenderedEvent
2 parents 7a18a61 + e91e48d commit 2b61c7a

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

lib/AppInfo/Application20.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use OCA\Deck\Db\AssignedUsersMapper;
3737
use OCA\Deck\Db\BoardMapper;
3838
use OCA\Deck\Db\CardMapper;
39+
use OCA\Deck\Listeners\BeforeTemplateRenderedListener;
3940
use OCA\Deck\Middleware\DefaultBoardMiddleware;
4041
use OCA\Deck\Middleware\ExceptionMiddleware;
4142
use OCA\Deck\Notification\Notifier;
@@ -46,6 +47,7 @@
4647
use OCP\AppFramework\Bootstrap\IBootContext;
4748
use OCP\AppFramework\Bootstrap\IBootstrap;
4849
use OCP\AppFramework\Bootstrap\IRegistrationContext;
50+
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
4951
use OCP\Collaboration\Resources\IProviderManager;
5052
use OCP\Comments\CommentsEntityEvent;
5153
use OCP\Comments\ICommentsManager;
@@ -84,8 +86,6 @@ public function __construct(array $urlParams = []) {
8486
}
8587

8688
public function boot(IBootContext $context): void {
87-
Util::addStyle('deck', 'deck');
88-
8989
$context->injectFn(Closure::fromCallable([$this, 'registerUserGroupHooks']));
9090
$context->injectFn(Closure::fromCallable([$this, 'registerCommentsEntity']));
9191
$context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler']));
@@ -112,6 +112,8 @@ public function register(IRegistrationContext $context): void {
112112

113113
$context->registerSearchProvider(DeckProvider::class);
114114
$context->registerDashboardWidget(DeckWidget::class);
115+
116+
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
115117
}
116118

117119
public function registerNotifications(NotificationManager $notificationManager): void {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
4+
*
5+
* @author Julius Härtl <jus@bitgrid.net>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
declare(strict_types=1);
25+
26+
27+
namespace OCA\Deck\Listeners;
28+
29+
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
30+
use OCP\EventDispatcher\Event;
31+
use OCP\EventDispatcher\IEventListener;
32+
use OCP\Util;
33+
34+
class BeforeTemplateRenderedListener implements IEventListener {
35+
public function handle(Event $event): void {
36+
if (!($event instanceof BeforeTemplateRenderedEvent)) {
37+
return;
38+
}
39+
40+
if (!$event->isLoggedIn()) {
41+
return;
42+
}
43+
Util::addStyle('deck', 'deck');
44+
}
45+
}

0 commit comments

Comments
 (0)