diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2017-03-18 03:37:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-18 03:37:52 +0300 |
commit | 794e5d45ed4a74a2970370b45b9fea85e5c08672 (patch) | |
tree | a913b4cc96cb9e45fbd4e874c3f03982df5a08e7 /core/Plugin/ControllerAdmin.php | |
parent | 60f4a409974918880c842cfd68f8af246032c122 (diff) |
New event that lets plugins trigger notifications in the admin area (#11483)
* New event that lets plugins trigger notifications in the admin area
They have to be triggered before assigning the notifications to the view and there is no other way to determine when a plugin is supposed to trigger notifications in the admin. Ideally, in the future we would even move the notifications above to CoreAdminHome or somewhere else eventually.
First thought of using `Controller.addAdminNotifications` as we often use this wording but then we would need to rather do `Piwik::postEvent('Controller.triggerAdminNotifications', &$notifications);` as otherwise nothing can be added.
Plugins could actually also use this event to cancel notifications where in the past it was needed to hide them via CSS.
Happy about any other naming suggestions but want to keep it "specific" to notifications and not something to general like `postEvent('Controller.renderAdminView, $view')`.
* document new event
Diffstat (limited to 'core/Plugin/ControllerAdmin.php')
-rw-r--r-- | core/Plugin/ControllerAdmin.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/Plugin/ControllerAdmin.php b/core/Plugin/ControllerAdmin.php index 7e6c679ddf..79ce898630 100644 --- a/core/Plugin/ControllerAdmin.php +++ b/core/Plugin/ControllerAdmin.php @@ -325,6 +325,26 @@ abstract class ControllerAdmin extends Controller self::notifyWhenDebugOnDemandIsEnabled('debug'); self::notifyWhenDebugOnDemandIsEnabled('debug_on_demand'); + /** + * Posted when rendering an admin page and notifications about any warnings or errors should be triggered. + * You can use it for example when you have a plugin that needs to be configured in order to work and the + * plugin has not been configured yet. It can be also used to cancel / remove other notifications by calling + * eg `Notification\Manager::cancel($notificationId)`. + * + * **Example** + * + * public function onTriggerAdminNotifications(Piwik\Widget\WidgetsList $list) + * { + * if ($pluginFooIsNotConfigured) { + * $notification = new Notification('The plugin foo has not been configured yet'); + * $notification->context = Notification::CONTEXT_WARNING; + * Notification\Manager::notify('fooNotConfigured', $notification); + * } + * } + * + */ + Piwik::postEvent('Controller.triggerAdminNotifications'); + $view->adminMenu = MenuAdmin::getInstance()->getMenu(); $notifications = $view->notifications; |