Before Build
apply_filters_ref_array( 'vikrestaurants_before_build_menu', bool $status, 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
- $status
-
(bool) True on success, false on failure.
- &$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 boolean $status True on success, false on failure.
* @param MenuShape &$menu The menu to build.
*/
add_filter('vikrestaurants_before_build_menu', function($status, &$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);
return true;
}, 10, 2);
Changelog
Version | Description |
---|---|
1.0 | Introduced. |
Last Update: 2023-09-08
Helpful?