diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-08-02 20:16:58 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-09-23 10:09:58 +0200 |
commit | 5694a04b700114fbf617d068a3a5ba9a4a8a1ca2 (patch) | |
tree | f261c30946ee1356a06d4a0df4732515e83722a5 /apps/comments/lib | |
parent | 606b4d5bf3a1c51b3e71a42dfc4add3596464ae9 (diff) | |
download | nextcloud-server-5694a04b700114fbf617d068a3a5ba9a4a8a1ca2.tar.gz nextcloud-server-5694a04b700114fbf617d068a3a5ba9a4a8a1ca2.zip |
Move over comments to the new event
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/comments/lib')
-rw-r--r-- | apps/comments/lib/AppInfo/Application.php | 17 | ||||
-rw-r--r-- | apps/comments/lib/Listener/LoadAdditionalScripts.php | 41 |
2 files changed, 49 insertions, 9 deletions
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php index 916345e4a5f..793d1e9f7be 100644 --- a/apps/comments/lib/AppInfo/Application.php +++ b/apps/comments/lib/AppInfo/Application.php @@ -26,10 +26,13 @@ namespace OCA\Comments\AppInfo; use OCA\Comments\Controller\Notifications; use OCA\Comments\EventHandler; use OCA\Comments\JSSettingsHelper; +use OCA\Comments\Listener\LoadAdditionalScripts; use OCA\Comments\Notification\Notifier; use OCA\Comments\Search\Provider; +use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCP\AppFramework\App; use OCP\Comments\CommentsEntityEvent; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Util; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -48,7 +51,8 @@ class Application extends App { public function register() { $server = $this->getContainer()->getServer(); - $dispatcher = $server->getEventDispatcher(); + /** @var IEventDispatcher $newDispatcher */ + $dispatcher = $server->query(IEventDispatcher::class); $this->registerSidebarScripts($dispatcher); $this->registerDavEntity($dispatcher); $this->registerNotifier(); @@ -57,16 +61,11 @@ class Application extends App { $server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]); } - protected function registerSidebarScripts(EventDispatcherInterface $dispatcher) { - $dispatcher->addListener( - 'OCA\Files::loadAdditionalScripts', - function() { - Util::addScript('comments', 'comments'); - } - ); + protected function registerSidebarScripts(IEventDispatcher $dispatcher) { + $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class); } - protected function registerDavEntity(EventDispatcherInterface $dispatcher) { + protected function registerDavEntity(IEventDispatcher $dispatcher) { $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) { $event->addEntityCollection('files', function($name) { $nodes = \OC::$server->getUserFolder()->getById((int)$name); diff --git a/apps/comments/lib/Listener/LoadAdditionalScripts.php b/apps/comments/lib/Listener/LoadAdditionalScripts.php new file mode 100644 index 00000000000..b1e9447beab --- /dev/null +++ b/apps/comments/lib/Listener/LoadAdditionalScripts.php @@ -0,0 +1,41 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> + * + * @author Roeland Jago Douma <roeland@famdouma.nl> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Comments\Listener; + +use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; + +class LoadAdditionalScripts implements IEventListener { + public function handle(Event $event): void { + if (!($event instanceof LoadAdditionalScriptsEvent)) { + return; + } + + Util::addScript('comments', 'comments'); + } + +} |