I’m stuck on customizing while upgrading from RT4 to RT5.
We tuned our menues via html/Elements/Tabs
to support our workflows. E.g. the Actions are direct accessible (not in a dropdown) while The Basics , Custom Fields and other not in the menue any more because one can access them via headlines of the Ticket’s metadata. With RT5 the html/Elements/Tabs
isn’t the same any more.
How to do this in RT5?
We use callbacks for this. In our case there are several different ones for different user groups but the basic idea is similar: under /opt/rt5/local/html
we have a directory for particular local callback such as LocalTabs
. Inside the /opt/rt5/local/html/LocalTabs
directory we have Elements/Tabs
directory tree and in that we have files for Privileged
and SelfService
in which the code to update the menus lives.
In these files we have the code to get the menus we want to play with and then manipulate them. Ours is really complicated because we’re looking at the current user’s group memberships and other aspects to alter the menus, but for example we get the actions menu with:
my $actions = PageMenu()->child('actions');
and to add a new menu we do:
my $requests = Menu->child( requests =>
title => loc('Requests'),
description => loc('Request submission forms'),
path => loc('/SelfService/Requests.html'),
);
We can then add stuff to it using $actions->child(...);
or remove them using $actions->delete('badmenukey');
.
In your case I assume you’ll be adding actions to the PageMenu
and then removing the actions menu?
Yes, that’s we want to do.
And we’ll be removing the ‘people’ and so on from the PageMenue, too.
Think I have to talk to a developer, I’m more planer and not that good in generating code
No developer availiable at the moment. I have to code myself. But I’m stuck how to access the ressources like $can
and $id
(ticket-id) and $page
in the Callback. Even $self
doesn’t work. I put it in a <%init> ... </%init>
block.
Funny: PageMenu->delete('basics');
works and deletes the entry, but PageMenu->child(...);
does not but raises internal server error complaining of missing package. Deleting and adding in the actions-menue is no problem, too.
I’m not able to add an entry to the PageMenue itself.
Is it possible to get some hints?
Have a nice weekend!
One week has gone.
I found a nice idea: enumerate the items in the ‘actions’ menue and give them a new parent. The debug-code shows, the ‘parent’ changes but the menue shows still the same. All actions are still shown in the ‘actions’ menue. See the stripped code below.
What I am missing?
<%init>
my $MainParent = undef;
my $item = undef;
$MainParent = PageMenu->child('actions')->parent; # I test existance of child('actions') before
if (my @actions = PageMenu->child('actions')->children) {
foreach $item ( @actions ) {
$item->parent($MainParent);
}
}
</%init>
Other idea is to create the PageMenu child by child. But how to find the valid KEYs for PageMenu->child('actions')->children
Could you put something like:
PageMenu->child('actions')->delete($item->title);
into your loop after you’ve given a new parent to the item?
Tried but doesn’t work. Then the menu-item is deleted at all.
You can not use the ‘title’ as KEY. The title is set with loc(Title)
so not the same.
I wonder how to enumerate the KEYs from PageMenu->child('actions')->children
. I don’t know how to do, yet. Think I have to work with the fix list.
It seems, setting a new parent hast no effekt. At least it is not the effect I expect.
https://docs.bestpractical.com/rt/5.0.5/RT/Interface/Web/Menu.html
Oh sorry, try this:
my $action = PageMenu()->child('actions');
my @keys;
if($action && $action->has_children) {
@keys = keys %{$action->{'children'}};
# Do whatever you need to do with the keys on the action menu here.
}
Great Jon, thank you!
That was the missing key. I’d like to mark your reply as ‘Solution’ but it lacks of some code-snipps before. Here is a short conclusion.
File: rt5/local/html/Callbacks/menues-priv/Elements/Tabs/Privileged
<%init>
if ( ($Path =~ m{^/Ticket/}) && ($Path !~ m{^/Ticket/Create.html}) ) {
# delete some items like this
PageMenu->child('basics') && PageMenu->delete('basics');
# enumerate the possible actions and do something with it
my $action = PageMenu()->child('actions');
my $item = undef;
my @keys;
if($action && $action->has_children) {
@keys = keys %{$action->{'children'}};
# Do whatever you need to do with the keys on the action menu here.
foreach $item ( @keys ) {
if ( $action->child($item)) {
PageMenu->child( $item => title => $action->child($item)->title, path => $action->child($item)->path );
# push other things to the child
$action->delete($item);
}
}
}
}
return 1;
</%init>
<%ARGS>
$Path => undef;
$Search_Args => undef;
$Has_Query => undef;
$ARGSRef => undef;
</%ARGS>
kind regards, Andre.
1 Like