fix!: Remove deprecated `RegisterWidgetEvent`

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/43439/head
Ferdinand Thiessen 3 months ago
parent e62c5d719d
commit a37b6c7e5f
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400

@ -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) {

@ -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',
);

@ -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',
);

@ -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 {

@ -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');
}
}

@ -248,7 +248,6 @@ return array(
'OCP\\Dashboard\\Model\\WidgetItem' => $baseDir . '/lib/public/Dashboard/Model/WidgetItem.php',
'OCP\\Dashboard\\Model\\WidgetItems' => $baseDir . '/lib/public/Dashboard/Model/WidgetItems.php',
'OCP\\Dashboard\\Model\\WidgetOptions' => $baseDir . '/lib/public/Dashboard/Model/WidgetOptions.php',
'OCP\\Dashboard\\RegisterWidgetEvent' => $baseDir . '/lib/public/Dashboard/RegisterWidgetEvent.php',
'OCP\\DataCollector\\AbstractDataCollector' => $baseDir . '/lib/public/DataCollector/AbstractDataCollector.php',
'OCP\\DataCollector\\IDataCollector' => $baseDir . '/lib/public/DataCollector/IDataCollector.php',
'OCP\\Defaults' => $baseDir . '/lib/public/Defaults.php',

@ -281,7 +281,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Dashboard\\Model\\WidgetItem' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetItem.php',
'OCP\\Dashboard\\Model\\WidgetItems' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetItems.php',
'OCP\\Dashboard\\Model\\WidgetOptions' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetOptions.php',
'OCP\\Dashboard\\RegisterWidgetEvent' => __DIR__ . '/../../..' . '/lib/public/Dashboard/RegisterWidgetEvent.php',
'OCP\\DataCollector\\AbstractDataCollector' => __DIR__ . '/../../..' . '/lib/public/DataCollector/AbstractDataCollector.php',
'OCP\\DataCollector\\IDataCollector' => __DIR__ . '/../../..' . '/lib/public/DataCollector/IDataCollector.php',
'OCP\\Defaults' => __DIR__ . '/../../..' . '/lib/public/Defaults.php',

@ -1,61 +0,0 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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 OCP\Dashboard;
use OCP\EventDispatcher\Event;
/**
* Class RegisterPanelEvent
*
* This event is dispatched to allow apps supporting older Nextcloud versions to
* still register their dashboard panels so that they are only constructed when
* they are needed. Deprecated right away so we can drop it again after 19 is EOL
* and backward compatible apps can use OCP\AppFramework\Bootstrap\IBootstrap
*
* @since 20.0.0
* @deprecated 20.0.0
*/
class RegisterWidgetEvent extends Event {
private $manager;
/**
* @param IManager $manager
* @since 20.0.0
*/
public function __construct(IManager $manager) {
parent::__construct();
$this->manager = $manager;
}
/**
* @param string $panelClass
* @since 20.0.0
*/
public function registerWidget(string $panelClass) {
$this->manager->lazyRegisterWidget($panelClass);
}
}
Loading…
Cancel
Save