Class dmitrybtn\yimp\MenuAdapter

Inheritancedmitrybtn\yimp\MenuAdapter » yii\base\BaseObject

Adapter for yii\bootstrap4\Nav, providing some additional functionality.

The following functionality is provided:

  1. Configure items visibility for desktops and mobiles separately.
  2. Generate an empty string if menu is invisible. Menu is invisible on current device if all link items are invisible on this device, even if there are visible labels (items with empty 'url' property).

Config array, passed to dmitrybtn\yimp\MenuAdapter::widget() differs from the original in the following:

  • mode: YIMP renders each menu in layout two times - for desktops and for mobile devices. In first case it sets this prop to dmitrybtn\yimp\Yimp::DESKTOP, in second - to dmitrybtn\yimp\Yimp::MOBILE. If item's visibleMode prop is set, this item will be rendered only if it's visibleMode value equals to this one.

  • items:

    • active: In original widget it is bool. Here it can be string, representing the mask, passed to dmitrybtn\yimp\RouteHelper::match(). If current route matches this mask, item will be activated. For example, this property is set to orders/*, item will be active on orders/create, orders/update, orders/item/create, and so on.
    • visibleMode: If you want to show menu item only on desktops, set it to Yimp::DESKTOP. For mobiles - YIMP::MOBILE.

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$mode string Mode for display menu. dmitrybtn\yimp\MenuAdapter
$route string Current route dmitrybtn\yimp\MenuAdapter
$visible boolean Whether all menu is visible dmitrybtn\yimp\MenuAdapter

Public Methods

Hide inherited methods

MethodDescriptionDefined By
widget() Creates Bootstrap Nav widget instance and renders it. dmitrybtn\yimp\MenuAdapter

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
adapt() Adapts menu items to Bootstrap Nav widget format. dmitrybtn\yimp\MenuAdapter
adaptItem() Adapts menu item to Bootstrap Nav widget format. dmitrybtn\yimp\MenuAdapter

Property Details

$mode protected property

Mode for display menu. Can be Yimp::DESKTOP or Yimp::MOBILE

protected string $mode null
$route protected property

Current route

protected string $route null
$visible protected property

Whether all menu is visible

protected boolean $visible false

Method Details

adapt() protected method

Adapts menu items to Bootstrap Nav widget format.

protected array adapt ( $items )
$items

Array List of menu items

return array

List of adapted menu items

adaptItem() protected method

Adapts menu item to Bootstrap Nav widget format.

protected array adaptItem ( $item )
$item

Array Menu item config

return array

Adapted menu item config

widget() public method

Creates Bootstrap Nav widget instance and renders it.

public string widget ( $config = [] )
$config array

Config array to be adapted for Bootstrap Nav widget.

throws Exception