Please enable JavaScript to view this site.

Navigation: Advanced topics > Events > Global events

Menu item: Modify

Scroll Prev Next More

Description

The ModifyMenuItem event is executed for each Menu item before the page is displayed in the browser. Use this event to modify or hide menu items.

Syntax

ModifyMenuItem($menuItem)

Arguments

$menuItem

a menu item object.

Return value

True: a menu item is shown.

 

False: a menu item is hidden.

Applies to pages

All pages with the Menu items.

Methods

getLinkType()

gets the link type.

Note: The link types are: Internal (link to a page generated by PHPRunner, e.g. List, Print etc.), External (link to any external web page), None (if menu item is not a link: for example, a group or separator).

 

getUrl()

gets the URL of an external link.

setUrl($url)

sets the URL of the link and makes it external.

getParams()

gets the parameters of an internal link.

setParams($params)

sets the parameters of an internal link. These parameters may be also set on the Choose page screen using the '...' button next to the List page.

Note: The parameters are a part of the link. E.g., if the parameters are foo=bar&bar=foo, the link is ...list.php?foo=bar&bar=foo.

 

setTitle($title)

sets the title of the link.

getTitle()

gets the title of the link.

getTable()

gets the table name that an internal link points to.

setTable($table)

sets the table name.

getPageType()

gets the page type (List, Add, etc.).

setPageType($pType)

sets the page type (List, Add, Search, Print, Report, Chart).

Examples

Adding parameters to a menu item

if ($menuItem->getLinkType() == 'External')
  {
    $menuItem->setUrl('https://localhost/mn1/carsmodels_list.php');
  }
  else if($menuItem->getLinkType() == 'Internal')
  {
    $menuItem->setParams('id=30');
    if ($menuItem->getTable() == 'carsmake')
     {
        $menuItem->setTable('carsmodels');
     }
  }
  else
  {
    return false;
  }
  return true;

Hide some menu items based on the group of the authorized user

If the menu item is a link to an internal application page, you can assign the table permissions.

 

However, if the menu item is an external link, you need to set the permissions directly in the Menu Item: Modify event.

 

if ($_SESSION["GroupID"]!="manager")
{
  $title = $menuItem->getTitle();
  if ($title=="Yahoo Finance")
    return false;
}
return true;

Display a record counter next to each menu item

The code checks if the menu item is an internal table or view and adds the number of records to the menu item title.

 

if($menuItem->getLinkType() == 'Internal')
{
global $tables_data;
$table=$menuItem->getTable();
include_once(getabspath("include/".$table."_settings.php"));
$ps = new ProjectSettings($table);
$table= $ps->getOriginalTableName();
$rs=DB::Query("select count(*) as c from " . AddTableWrappers($table));
$data = $rs->fetchAssoc();
$menuItem->setTitle($menuItem->getTitle() . " (". $data["c"] . ")");
}
return true;

Hide some menu items in the Mobile mode

  if ($menuItem->getTable() == 'Cars' && MobileDetected()) {
      return false;
  }
  return true;

Recommended predefined actions and sample events:

Check to see if a specific record exists

See also:

Choose pages screen

Menu builder

Working with page elements

RunnerPage class: hideItem()

Datasource tables

Session keys

Save user data in session variables

Database API: fetchAssoc()

Database API: Query()

Javascript API: toggleItem()

Events. Redirect to another page

 

Created with Help+Manual 7 and styled with Premium Pack Version 3 © by EC Software