This code works if i want to manually override the menu text:
Code: Select all
function MenuItem_Adding($item)
{
if ($item->Text == "Science faculty"){
$item->Text = "Art faculty";
}
}
But I needed a more flexible solution using a table instead to define the new text for the menu items, as my project was being rolled out to different sites who use different department names, which they needed to be able to easily edit themselves.
I created a table MenuNames
like this:
Code: Select all
id, OldName, NewName
OldName contains the original name for the menu item as i defined in PHPMaker, NewName contains the name to override that with.
In Global>All Pages>MenuItem_Adding use this:
Code: Select all
function MenuItem_Adding($item){
$menuitems = ExecuteRows("SELECT OldName, NewName FROM MenuNames");
if(count($menuitems)>0){
for ($i=0; $i<count($menuitems); $i++){
$OldName=$menuitems[$i][0];
$NewName=$menuitems[$i][1];
if ($item->Text == $OldName){
$item->Text = $NewName;
}
}
}
return true;
}