Your cart is empty!
Before Build
public function onBeforeBuildVikRestaurantsMenu(MenuShape &$menu)
Fires before building the back-end main menu of the component.
Description
Plugins can use this hook to manipulate the back-end menu of VikRestaurants at runtime.
It is useful in case you need to introduce additional separators and/or menu items. Otherwise, it is also possible to remove certain default menu items, such as the payments section.
Parameters
- &$menu
-
(MenuShape) The current menu instance. Since the argument is passed by reference, any changes applied to the instance will immediately take effect.
Return Value
None.
Example
The example below adds the Rooms Closures menu item after Rooms, within the Restaurant category, and removes the Menus and Products items from the same category.
/**
* Trigger action to allow the plugins to manipulate the back-end menu of VikRestaurants.
*
* @param MenuShape &$menu The menu to build.
*
* @return void
*/
public function onBeforeBuildVikRestaurantsMenu(&$menu)
{
$input = JFactory::getApplication()->input;
// Get "Restaurant" separator. It can be found at index [1],
// after the "Dashboard" category.
$restaurant = $menu->get(1);
// delete "Products" menu item
$restaurant->unsetChild([
'title' => 'Products',
]);
// delete "Menus" menu item
$restaurant->unsetChild([
'title' => 'Menus',
]);
// create "Rooms Closures" menu item
$closures = MenuFactory::createItem(
'Room Closures',
'index.php?option=com_vikrestaurants&view=roomclosures',
$input->get('view') == 'roomclosures'
);
// set icon for rooms closures
$closures->setCustom('calendar-times-alt');
$items = [];
// copy menu items in order to push
// the rooms closures wherever we want
foreach ($restaurant->getMenu() as $item) {
// copy item
$items[] = $item;
// search if we copied the rooms menu item
if ($item->getTitle() == 'Rooms') {
// include closures after the rooms
$items[] = $closures;
}
}
// setup menu items again
$restaurant->setMenu($items);
}
Changelog
Version | Description |
---|---|
1.7 | Introduced. |
Last Update: 2023-12-29 14:15
Helpful?