Your cart is empty!
Before Build
do_action_ref_array( 'vikrestaurants_before_build_menu', MenuShape &$menu )
Fires before building the back-end main menu of the plugin.
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.
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.
*/
add_action('vikrestaurants_before_build_menu', function(&$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(array(
'title' => __('Products', 'vikrestaurants'),
));
// delete "Menus" menu item
$restaurant->unsetChild(array(
'title' => __('Menus', 'vikrestaurants'),
));
// create "Rooms Closures" menu item
$closures = MenuFactory::createItem(
__('Rooms Closures', 'vikrestaurants'),
'admin.php?page=vikrestaurants&view=roomclosures', $input->get('view') == 'roomclosures'
);
// set icon for rooms closures
$closures->setCustom('calendar-times-o');
$items = array();
$rooms_name = __('Rooms', 'vikrestaurants');
// 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_name)
{
// include closures after the rooms
$items[] = $closures;
}
}
// setup menu items again
$restaurant->setMenu($items);
}); Changelog
| Version | Description |
|---|---|
| 1.5.5 | Removed $status argument. |
| 1.0 | Introduced. |
Last Update: 1 week ago
Helpful?