From c08d36b059042ab9ed3e2e0f4ff618a47b0db0a2 Mon Sep 17 00:00:00 2001
From: Ronaldo Richieri <ronaldo@bestpractical.com>
Date: Thu, 22 Feb 2024 16:57:02 -0300
Subject: [PATCH] Add callbacks to dashboard portlet rendering

In some cases, we might want to change portlet attributes
before rendering it, or even update HasResults attribute
after the portlet has been rendered.

This patch adds callbacks before and after rendering
portlets.
---
 share/html/Dashboards/Elements/ShowPortlet/dashboard | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/share/html/Dashboards/Elements/ShowPortlet/dashboard b/share/html/Dashboards/Elements/ShowPortlet/dashboard
index 14b343bb28a..164c229631b 100644
--- a/share/html/Dashboards/Elements/ShowPortlet/dashboard
+++ b/share/html/Dashboards/Elements/ShowPortlet/dashboard
@@ -77,6 +77,10 @@ Abort("Possible recursive dashboard detected.") if $Depth > 8;
 <%perl>
 local $session{CurrentUser} = $session{ContextUser};
 for my $portlet (@panes) {
+
+    $m->callback(CallbackName => 'BeforeComponent', Dashboard => $Dashboard,
+        HasResults => $HasResults, Portlet => $portlet, ARGSRef => \%ARGS);
+
     $m->comp($portlet->{portlet_type},
         Portlet    => $portlet,
         Rows       => $Rows,
@@ -86,6 +90,10 @@ for my $portlet (@panes) {
         Depth      => $Depth + 1,
         HasResults => $HasResults
     );
+
+    $m->callback(CallbackName => 'AfterComponent', Dashboard => $Dashboard,
+        HasResults => $HasResults, Portlet => $portlet, ARGSRef => \%ARGS);
+
 }
 </%perl>