Skip to content

Commit

Permalink
Fixed issue #15879: Plugin menu events not implemented in V4
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Feb 17, 2020
1 parent 81a2f3a commit fe349f0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
9 changes: 8 additions & 1 deletion application/controllers/admin/surveyadmin.php
Expand Up @@ -2523,6 +2523,12 @@ public function getSurveyTopbar($sid, $saveButton = false)
App()->getPluginManager()->dispatchEvent($event);
$extraToolsMenuItems = $event->get('menuItems');

// Add new menus in survey bar
$event = new PluginEvent('beforeSurveyBarRender', $this);
$event->set('surveyId', $oSurvey->sid);
App()->getPluginManager()->dispatchEvent($event);
$beforeSurveyBarRender = $event->get('menus');

return Yii::app()->getController()->renderPartial(
'/admin/survey/topbar/survey_topbar',
array(
Expand All @@ -2548,7 +2554,8 @@ public function getSurveyTopbar($sid, $saveButton = false)
'hasSurveyActivationPermission' => $hasSurveyActivationPermission,
'hasResponsesStatisticsReadPermission' => $hasResponsesStatisticsReadPermission,
'addSaveButton' => $saveButton,
'extraToolsMenuItems' => $extraToolsMenuItems
'extraToolsMenuItems' => $extraToolsMenuItems ?? [],
'beforeSurveyBarRender' => $beforeSurveyBarRender ?? []
),
false,
false
Expand Down
61 changes: 61 additions & 0 deletions application/views/admin/survey/topbar/survey_topbar.php
Expand Up @@ -420,6 +420,67 @@
array_push($topbar['alignment']['left']['buttons'], $button_statistics);
}

if (!empty($beforeSurveyBarRender)) {
foreach ($beforeSurveyBarRender as $i => $menu) {
if ($menu->isDropDown()) {
$dropdown = [
'class' => 'btn-group hidden-xs',
'id' => 'plugin_dropdown' . $i,
'main_button' => [
'class' => 'dropdown-toggle',
'datatoggle' => 'dropdown',
'ariahaspopup' => 'true',
'ariaexpanded' => 'false',
'icon' => $menu->getIconClass(),
'name' => $menu->getLabel(),
'iconclass' => 'caret',
'id' => 'plugin_dropdown' . $i
],
'dropdown' => [
'class' => 'dropdown-menu',
'arialabelledby' => 'plugin_dropdown' . $i,
'items' => [],
],
];
foreach ($menu->getMenuItems() as $j => $item) {
// TODO: Code duplication.
if ($item->isDivider()) {
// Divider
$item = [
'role' => 'seperator',
'class' => 'divider',
'id' => 'divider---1' . $i
];
} elseif ($item->isSmallText()) {
// Regenerate question codes
$item = [
'class' => 'dropdown-header',
'name' => $item->getLabel()
];
} else {
$item = [
'url' => $item->getHref(),
'icon' => $item->getIconClass(),
'name' => $item->getLabel(),
'id' => 'plugin_button' . $i
];
}
array_push($dropdown['dropdown']['items'], $item);
}
array_push($topbar['alignment']['left']['buttons'], $dropdown);
} else {
$button = [
'class' => 'pjax',
'id' => 'plugin_menu' . $i,
'url' => $menu->getHref(),
'name' => $menu->getLabel(),
'icon' => $menu->getIconClass()
];
array_push($topbar['alignment']['left']['buttons'], $button);
}
}
}

$buttons['save'] = [
'name' => gT('Save'),
'id' => 'save-button',
Expand Down

0 comments on commit fe349f0

Please sign in to comment.