diff options
author | Julius Härtl <jus@bitgrid.net> | 2024-02-09 09:40:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-09 09:40:01 +0100 |
commit | 6b1ea794920c89b423b072b1923b3126a2b8be2a (patch) | |
tree | f8adba9ffd725633973ba3b5440ab968437e2c18 /apps | |
parent | 7ff6cbc1b8aba9edcc60a2813776a1a7b74410dd (diff) | |
parent | a37b6c7e5fe1d55d877c502987a7dfbeee2ed7b3 (diff) | |
download | nextcloud-server-6b1ea794920c89b423b072b1923b3126a2b8be2a.tar.gz nextcloud-server-6b1ea794920c89b423b072b1923b3126a2b8be2a.zip |
Merge pull request #43439 from nextcloud/fix/remove-deprecated-event
fix!: Remove deprecated `RegisterWidgetEvent`
Diffstat (limited to 'apps')
5 files changed, 60 insertions, 12 deletions
diff --git a/apps/dashboard/lib/Controller/DashboardController.php b/apps/dashboard/lib/Controller/DashboardController.php index a2605e69f4c..1c7b98dc3ea 100644 --- a/apps/dashboard/lib/Controller/DashboardController.php +++ b/apps/dashboard/lib/Controller/DashboardController.php @@ -38,7 +38,6 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; use OCP\Dashboard\IManager; use OCP\Dashboard\IWidget; -use OCP\Dashboard\RegisterWidgetEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IL10N; @@ -89,8 +88,6 @@ class DashboardController extends Controller { \OCP\Util::addStyle('dashboard', 'dashboard'); \OCP\Util::addScript('dashboard', 'main', 'theming'); - $this->eventDispatcher->dispatchTyped(new RegisterWidgetEvent($this->dashboardManager)); - $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar'); $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)); $widgets = array_map(function (IWidget $widget) { diff --git a/apps/weather_status/composer/composer/autoload_classmap.php b/apps/weather_status/composer/composer/autoload_classmap.php index 00626b48042..0a76e820a0a 100644 --- a/apps/weather_status/composer/composer/autoload_classmap.php +++ b/apps/weather_status/composer/composer/autoload_classmap.php @@ -10,6 +10,7 @@ return array( 'OCA\\WeatherStatus\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', 'OCA\\WeatherStatus\\Capabilities' => $baseDir . '/../lib/Capabilities.php', 'OCA\\WeatherStatus\\Controller\\WeatherStatusController' => $baseDir . '/../lib/Controller/WeatherStatusController.php', + 'OCA\\WeatherStatus\\Listeners\\BeforeTemplateRenderedListener' => $baseDir . '/../lib/Listeners/BeforeTemplateRenderedListener.php', 'OCA\\WeatherStatus\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php', 'OCA\\WeatherStatus\\Service\\WeatherStatusService' => $baseDir . '/../lib/Service/WeatherStatusService.php', ); diff --git a/apps/weather_status/composer/composer/autoload_static.php b/apps/weather_status/composer/composer/autoload_static.php index 1891eb468e2..c9c58f836a8 100644 --- a/apps/weather_status/composer/composer/autoload_static.php +++ b/apps/weather_status/composer/composer/autoload_static.php @@ -25,6 +25,7 @@ class ComposerStaticInitWeatherStatus 'OCA\\WeatherStatus\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', 'OCA\\WeatherStatus\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php', 'OCA\\WeatherStatus\\Controller\\WeatherStatusController' => __DIR__ . '/..' . '/../lib/Controller/WeatherStatusController.php', + 'OCA\\WeatherStatus\\Listeners\\BeforeTemplateRenderedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeTemplateRenderedListener.php', 'OCA\\WeatherStatus\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php', 'OCA\\WeatherStatus\\Service\\WeatherStatusService' => __DIR__ . '/..' . '/../lib/Service/WeatherStatusService.php', ); diff --git a/apps/weather_status/lib/AppInfo/Application.php b/apps/weather_status/lib/AppInfo/Application.php index e69215148e0..19cfd643a7e 100644 --- a/apps/weather_status/lib/AppInfo/Application.php +++ b/apps/weather_status/lib/AppInfo/Application.php @@ -26,14 +26,12 @@ declare(strict_types=1); namespace OCA\WeatherStatus\AppInfo; use OCA\WeatherStatus\Capabilities; +use OCA\WeatherStatus\Listeners\BeforeTemplateRenderedListener; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\Dashboard\RegisterWidgetEvent; -use OCP\EventDispatcher\Event; -use OCP\EventDispatcher\IEventDispatcher; -use OCP\Util; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; /** * Class Application @@ -52,11 +50,6 @@ class Application extends App implements IBootstrap { */ public function __construct(array $urlParams = []) { parent::__construct(self::APP_ID, $urlParams); - - $dispatcher = $this->getContainer()->query(IEventDispatcher::class); - $dispatcher->addListener(RegisterWidgetEvent::class, function (Event $e) { - Util::addScript(self::APP_ID, 'weather-status'); - }); } /** @@ -65,6 +58,7 @@ class Application extends App implements IBootstrap { public function register(IRegistrationContext $context): void { // Register OCS Capabilities $context->registerCapability(Capabilities::class); + $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); } public function boot(IBootContext $context): void { diff --git a/apps/weather_status/lib/Listeners/BeforeTemplateRenderedListener.php b/apps/weather_status/lib/Listeners/BeforeTemplateRenderedListener.php new file mode 100644 index 00000000000..5b08661337b --- /dev/null +++ b/apps/weather_status/lib/Listeners/BeforeTemplateRenderedListener.php @@ -0,0 +1,55 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de> + * + * @author Ferdinand Thiessen <opensource@fthiessen.de> + * + * @license AGPL-3.0-or-later + * + * 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\WeatherStatus\Listeners; + +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; + +/** + * @template-implements IEventListener<BeforeTemplateRenderedEvent> + */ +class BeforeTemplateRenderedListener implements IEventListener { + + /** + * Inject our status widget script when the dashboard is loaded + * We need to do it like this because there is currently no PHP API for registering "status widgets" + */ + public function handle(Event $event): void { + if (!($event instanceof BeforeTemplateRenderedEvent)) { + return; + } + + // Only handle the dashboard + if ($event->getResponse()->getApp() !== 'dashboard') { + return; + } + + Util::addScript('weather_status', 'weather-status'); + } +} |