5.3. The menu

The menu in the administration interface is dynamically generated, letting all installed modules add new items and folders to it. There is a set of classes under the EBox::Menu namespace that can be used to build menu structures. The important ones are EBox::Menu::Item and EBox::Menu::Folder.

The constructor for EBox::Menu::Item takes two named arguments, text and url. url should be relative to the root path for the configuration interface, for example the firewall packet filtering page has Firewall/Filter as its url.

The EBox::Menu::Folder constructor does not take an url argument, but it takes a name one. The name is used internally as an identifier in the javascript menu implementation.

Both items and folders have an optional order argument in their constructors, it should be an integer between 1 and 10, items in the menu are ordered from lower to higher values. The default is 5.

A folder may contain items, so you can add EBox::Menu::Item instances to a EBox::Menu::Folder.

Finally, the way to add menu items and/or folders to the menu is to implement the menu method in your module. This method gets a EBox::Menu::Root instance as an argument, and you can add as many items and folders to it as you want. This is the menu function for the firewall module:

Example 5.15. Adding folders and items to the menu

sub menu
{
	my ($self, $root) = @_;
	my $folder = new EBox::Menu::Folder('name' => 'Firewall',
				'text' => __('Firewall'),
				'order' => 4);

	$folder->add(new EBox::Menu::Item('url' => 'Firewall/Filter',
				'text' => __('Packet Filter')));
	$folder->add(new EBox::Menu::Item('url' => 'Firewall/Redirects',
				'text' => __('Redirects')));

	$root->add($folder);
}