Extra menus event: Difference between revisions
From LimeSurvey Manual
No edit summary |
No edit summary |
||
Line 39: | Line 39: | ||
And this example shows how to add a button menu item on the left side of the admin menu: | 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"> | <syntaxhighlight lang="php"> | ||
Line 45: | Line 45: | ||
$buttonTestOptions = [ | $buttonTestOptions = [ | ||
'buttonId' => 'test-button', | 'buttonId' => 'test-button', | ||
'label' => | 'label' => 'Test button', | ||
'href' => 'https://limesurvey.org', | 'href' => 'https://limesurvey.org', | ||
'iconClass' => 'fa fa-link', | 'iconClass' => 'fa fa-link', | ||
'openInNewTab' => true, | 'openInNewTab' => true, | ||
'isPrepended' => true, | 'isPrepended' => true, | ||
'tooltip' => | 'tooltip' => 'You can add a tooltip here', | ||
]; | ]; | ||
Revision as of 08:34, 7 October 2022
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 ExtraMenu(array(
'isDropDown' => true,
'menuItems' => array(
new ExtraMenuItem(null),
new ExtraMenuItem(null),
new ExtraMenuItem(array('isDivider' => true)),
new ExtraMenuItem(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 |
isPrepended | Returns true if the item is displayed on the left side of the admin menu |
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 |