From b9ae0bbdf8103626a298b4d9baab55bf7be104d1 Mon Sep 17 00:00:00 2001 From: Jim Brandt Date: Tue, 7 Jan 2025 10:50:59 -0500 Subject: [PATCH] Add new callbacks to modify the main page navigation menu We no longer build the main page navigation on every request in the same mason template as the page menu, so extensions that used /Elements/Tabs Privileged and SelfService to modify the top page menu will no longer work. Add a new callback that can be used for this purpose. --- devel/docs/UPGRADING-6.0 | 15 +++++++++++++++ lib/RT/Interface/Web/MenuBuilder.pm | 11 +++++++++-- share/html/Elements/Header | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/devel/docs/UPGRADING-6.0 b/devel/docs/UPGRADING-6.0 index 283e58c308..8acdd7f228 100644 --- a/devel/docs/UPGRADING-6.0 +++ b/devel/docs/UPGRADING-6.0 @@ -157,6 +157,21 @@ In addition to the above, the following callbacks changed or moved in RT 6. =over +=item /Elements/Tabs Privileged and and SelfService + +These callbacks are used to modify RT's top menu and page menu, usually to +add new things to the menus. The previous callbacks are still available, +but RT no longer rebuilds the top navigation menu on every request. If you +previously used one of these callbacks to modify the top navigation menu +via C, that will no longer be defined or updated consistently in +the existing callbacks. + +To add items to the main page menu, you can use two new callbacks added +for this purpose: + + /Elements/Header PrivilegedMainNav + /Elements/Header SelfServiceMainNav + =item /Prefs/Other.html BeforeOption This callback is still in the same location on the rendered page, but it has diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm index 58743886e3..3e890cf4f9 100644 --- a/lib/RT/Interface/Web/MenuBuilder.pm +++ b/lib/RT/Interface/Web/MenuBuilder.pm @@ -62,7 +62,8 @@ sub QueryString { HTML::Mason::Commands::QueryString( @_ ); } sub ShortenSearchQuery { HTML::Mason::Commands::ShortenSearchQuery( @_ ); } sub BuildMainNav { - my $top = shift; + my $top = shift; + my %args = @_; my $current_user = $HTML::Mason::Commands::session{CurrentUser}; @@ -341,6 +342,9 @@ sub BuildMainNav { if ( $current_user->Name ) { $about_me->child( logout => title => loc('Logout'), path => '/NoAuth/Logout.html' ); } + + # Added in RT6 to handle main menu changes + $HTML::Mason::Commands::m->callback( CallbackName => 'PrivilegedMainNav', ARGSRef => \%args, CallbackPage => '/Elements/Header' ); } sub BuildPageNav { @@ -1948,7 +1952,8 @@ sub _BuildAdminPageMenu { } sub BuildSelfServiceMainNav { - my $top = shift; + my $top = shift; + my %args = @_; my $current_user = $HTML::Mason::Commands::session{CurrentUser}; @@ -2003,6 +2008,8 @@ sub BuildSelfServiceMainNav { $about_me->child( logout => title => loc('Logout'), path => '/NoAuth/Logout.html' ); } + # Added in RT6 to handle main menu changes + $HTML::Mason::Commands::m->callback( CallbackName => 'SelfServiceMainNav', ARGSRef => \%args, CallbackPage => '/Elements/Header' ); } sub BuildSelfServicePageNav { diff --git a/share/html/Elements/Header b/share/html/Elements/Header index 0767846a38..6beafe761e 100644 --- a/share/html/Elements/Header +++ b/share/html/Elements/Header @@ -205,10 +205,10 @@ if ( $session{CurrentUser} && $session{CurrentUser}->Id ) { require RT::Interface::Web::MenuBuilder; if ( $request_path =~ m{^/SelfService/} ) { - RT::Interface::Web::MenuBuilder::BuildSelfServiceMainNav( Menu() ); + RT::Interface::Web::MenuBuilder::BuildSelfServiceMainNav( Menu(), %ARGS ); } else { - RT::Interface::Web::MenuBuilder::BuildMainNav( Menu() ); + RT::Interface::Web::MenuBuilder::BuildMainNav( Menu(), %ARGS ); } my $app_overflow = Menu()->child( overflow => title => loc('More'), sort_order => 99999);