Extra menus event: Difference between revisions
From LimeSurvey Manual
No edit summary |
|||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Description of the event to generate extra menus at top bar (besides configuration, logout, etc). | Description of the event to generate extra menus at top bar (besides configuration, logout, etc). | ||
Three types of menus: | |||
* Dropdown | * Dropdown | ||
* Link | * Link | ||
* Button (since LimeSurvey 5.4) | |||
For dropdown, we have two kinds of menu items: | For dropdown, we have two kinds of menu items: | ||
Line 13: | Line 14: | ||
Plugin will set property <code>extraMenus</code>. Each element in that array must implement interface <code>ExtraMenuInterface</code>. | Plugin will set property <code>extraMenus</code>. Each element in that array must implement interface <code>ExtraMenuInterface</code>. | ||
== | == Examples == | ||
This example with create a dropdown menu with three empty menu items and one divider: | This example with create a dropdown menu with three empty menu items and one divider: | ||
Line 21: | Line 22: | ||
$event = $this->getEvent(); | $event = $this->getEvent(); | ||
$event->set('extraMenus', array( | $event->set('extraMenus', array( | ||
new | new Menu(array( | ||
'isDropDown' => true, | 'isDropDown' => true, | ||
'menuItems' => array( | 'menuItems' => array( | ||
new | new MenuItem(null), | ||
new | new MenuItem(null), | ||
new | new MenuItem(array('isDivider' => true)), | ||
new | new MenuItem(null) | ||
) | ) | ||
)) | )) | ||
)); | )); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
How it would look: | How it would look: | ||
[[File:extramenu.jpg]] | [[File:extramenu.jpg]] | ||
And this example shows how to add a button menu item on the left side of the admin menu (since LimeSurvey 5.4): | |||
<syntaxhighlight lang="php"> | |||
$event = $this->getEvent(); | |||
$buttonTestOptions = [ | |||
'buttonId' => 'test-button', | |||
'label' => 'Test button', | |||
'href' => 'https://limesurvey.org', | |||
'iconClass' => 'fa fa-link', | |||
'openInNewTab' => true, | |||
'isPrepended' => true, | |||
'tooltip' => 'You can add a tooltip here', | |||
]; | |||
$menuTestButton = new \LimeSurvey\Menu\MenuButton($buttonTestOptions); | |||
$event->append('extraMenus', [$menuTestButton]); | |||
</syntaxhighlight> | |||
== Interfaces == | == Interfaces == | ||
Line 44: | Line 63: | ||
|- | |- | ||
| isDropDown || Returns true if this menu is a dropdown menu | | isDropDown || Returns true if this menu is a dropdown menu | ||
|- | |||
| isSmallText || Returns true if this item is a small text header (uses label as text) | |||
|- | |- | ||
| getLabel || Returns the actual name of the menu | | getLabel || Returns the actual name of the menu | ||
|- | |||
| getIconClass || Return CSS class for icon to display left of link | |||
|- | |- | ||
| getHref || If it's not a dropdown menu, this is just for the link | | getHref || If it's not a dropdown menu, this is just for the link | ||
|- | |- | ||
| getMenuItems || Return array of dropdown menu items | | getMenuItems || Return array of dropdown menu items | ||
|- | |||
| isInMiddleSection || Returns true if the item is displayed in the middle section of the admin menu (LS6) | |||
|- | |||
| isPrepended || Returns true if the item is displayed on the left side of the admin menu section | |||
|- | |||
| isButton || Returns true if the item is a button | |||
|} | |} | ||
Line 60: | Line 89: | ||
|- | |- | ||
| getLabel || The text for the link | | getLabel || The text for the link | ||
|- | |||
| isDivider || Return true if the item is a divider | |||
|} | |} |
Latest revision as of 12:54, 28 April 2023
Description of the event to generate extra menus at top bar (besides configuration, logout, etc).
Three types of menus:
- Dropdown
- Link
- Button (since LimeSurvey 5.4)
For dropdown, we have two kinds of menu items:
- Link
- Divider
The event itself is called beforeAdminMenuRender
.
Plugin will set property extraMenus
. Each element in that array must implement interface ExtraMenuInterface
.
Examples
This example with create a dropdown menu with three empty menu items and one divider:
$event = $this->getEvent();
$event->set('extraMenus', array(
new Menu(array(
'isDropDown' => true,
'menuItems' => array(
new MenuItem(null),
new MenuItem(null),
new MenuItem(array('isDivider' => true)),
new MenuItem(null)
)
))
));
How it would look:
And this example shows how to add a button menu item on the left side of the admin menu (since LimeSurvey 5.4):
$event = $this->getEvent();
$buttonTestOptions = [
'buttonId' => 'test-button',
'label' => 'Test button',
'href' => 'https://limesurvey.org',
'iconClass' => 'fa fa-link',
'openInNewTab' => true,
'isPrepended' => true,
'tooltip' => 'You can add a tooltip here',
];
$menuTestButton = new \LimeSurvey\Menu\MenuButton($buttonTestOptions);
$event->append('extraMenus', [$menuTestButton]);
Interfaces
Method | Description |
---|---|
isDropDown | Returns true if this menu is a dropdown menu |
isSmallText | Returns true if this item is a small text header (uses label as text) |
getLabel | Returns the actual name of the menu |
getIconClass | Return CSS class for icon to display left of link |
getHref | If it's not a dropdown menu, this is just for the link |
getMenuItems | Return array of dropdown menu items |
isInMiddleSection | Returns true if the item is displayed in the middle section of the admin menu (LS6) |
isPrepended | Returns true if the item is displayed on the left side of the admin menu section |
isButton | Returns true if the item is a button |
Each menu item returned by getMenuItems
must implement the interface ExtraMenuItemInterface
Method | Description |
---|---|
getHref | As above, used for link in dropdown item |
getLabel | The text for the link |
isDivider | Return true if the item is a divider |