Skip to content

Commit

Permalink
Add new callbacks to modify the main page navigation menu
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cbrandtbuffalo committed Jan 7, 2025
1 parent d43e849 commit 6e02a0e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
24 changes: 24 additions & 0 deletions devel/docs/UPGRADING-6.0
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,30 @@ 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 main page navigation
via C<Menu()>, 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

As noted above, the main page navigation is no longer rebuilt on every
page load. If you have code that can change menus per page load, you
can force a full page reload by setting this header:

HX-Trigger: {"reloadRequired":""}

But we would encourage extension authors to do this only when absolutely
necessary since it negates some of the advantages of htmx.

=item /Prefs/Other.html BeforeOption

This callback is still in the same location on the rendered page, but it has
Expand Down
9 changes: 9 additions & 0 deletions lib/RT/Interface/Web/MenuBuilder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ sub ShortenSearchQuery { HTML::Mason::Commands::ShortenSearchQuery( @_ ); }

sub BuildMainNav {
my $top = shift;
my $request_path = shift;
my %args = ( @_ );

my $current_user = $HTML::Mason::Commands::session{CurrentUser};

Expand Down Expand Up @@ -341,6 +343,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', Path => $request_path, ARGSRef => \%args, CallbackPage => '/Elements/Header' );
}

sub BuildPageNav {
Expand Down Expand Up @@ -1949,6 +1954,8 @@ sub _BuildAdminPageMenu {

sub BuildSelfServiceMainNav {
my $top = shift;
my $request_path = shift;
my %args = ( @_ );

my $current_user = $HTML::Mason::Commands::session{CurrentUser};

Expand Down Expand Up @@ -2003,6 +2010,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', Path => $request_path, ARGSRef => \%args, CallbackPage => '/Elements/Header' );
}

sub BuildSelfServicePageNav {
Expand Down
4 changes: 2 additions & 2 deletions share/html/Elements/Header
Original file line number Diff line number Diff line change
Expand Up @@ -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(), $request_path, %ARGS );
}
else {
RT::Interface::Web::MenuBuilder::BuildMainNav( Menu() );
RT::Interface::Web::MenuBuilder::BuildMainNav( Menu(), $request_path, %ARGS );
}

my $app_overflow = Menu()->child( overflow => title => loc('More'), sort_order => 99999);
Expand Down

0 comments on commit 6e02a0e

Please sign in to comment.