VikRestaurants Plugin Events

These events are related to the main menu displayed within the back-end section of VikRestaurants.

onBeforeBuildVikRestaurantsMenu

Trigger event to allow the plugins to manipulate the back-end menu of VikRestaurants.

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.

Return Value

None.

@since 1.8

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 event to allow the plugins to manipulate the back-end menu of VikRestaurants.
 *
 * @param   MenuShape  &$menu   The menu to build.
 *
 * @return  void
 *
 * @since   1.8
 */
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(array(
        'title' => JText::_('VRMENUMENUSPRODUCTS'),
    ));

    // delete "Menus" menu item
    $restaurant->unsetChild(array(
        'title' => JText::_('VRMENUMENUS')
    ));

    // create "Rooms Closures" menu item
    $closures = MenuFactory::createItem('Rooms Closures', 'index.php?option=com_vikrestaurants&view=roomclosures', $input->get('view') == 'roomclosures');
    // set icon for rooms closures
    $closures->setCustom('calendar-times-o');

    $items = array();

    // 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() == JText::_('VRMENUROOMS'))
        {
            // include closures after the rooms
            $items[] = $closures;
        }
    }

    // setup menu items again
    $restaurant->setMenu($items);
}

onBeforeDefineVikRestaurantsMenuType

Trigger event to allow the plugins to choose a specific type to use for the layout of the back-end menu.

By default, VikRestaurants supports only 2 menu types:

  • leftboard, vertical layout placed on the left side (default one);
  • horizontal, horizontal layout placed above the component contents.

In case you wish to create your own layout, you can define all the required classes here:

/components/com_vikrestaurants/helpers/library/menu/[MENU_TYPE]/

All the layouts should be placed here instead:

/administrator/components/com_vikrestaurants/layouts/menu/[MENU_TYPE]/

In case the specified layout doesn't exist, an exception will be thrown.

Parameters

The event doesn't accept any arguments.

Return Value

String. The menu type to use.

@since 1.8

Example

The example below shows how you can use the horizontal layout.

/**
 * Trigger event to allow the plugins to choose a specific type to
 * use for the layout of the back-end menu.
 * By default, VikRestaurants supports only 2 menu types:
 * - 'leftboard', vertical layout placed on the left side;
 * - 'horizontal', horizontal layout placed above the component contents.
 *
 * @return  string  The menu type to use.
 *
 * @since   1.8
 */
public function onBeforeDefineVikRestaurantsMenuType()
{
    // check if we have Joomla 4.0+
    $j4 = VersionListener::isJoomla40();

    if ($j4)
    {
        // return horizontal layout only in case of J4
        return 'horizontal';
    }

    // leave menu as it is
}

This site uses cookies. By continuing to browse you accept their use. Further information