diff --git a/application/controllers/admin/surveyadmin.php b/application/controllers/admin/surveyadmin.php index 5b12af8fa51..01696aee75c 100644 --- a/application/controllers/admin/surveyadmin.php +++ b/application/controllers/admin/surveyadmin.php @@ -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( @@ -2548,7 +2554,8 @@ public function getSurveyTopbar($sid, $saveButton = false) 'hasSurveyActivationPermission' => $hasSurveyActivationPermission, 'hasResponsesStatisticsReadPermission' => $hasResponsesStatisticsReadPermission, 'addSaveButton' => $saveButton, - 'extraToolsMenuItems' => $extraToolsMenuItems + 'extraToolsMenuItems' => $extraToolsMenuItems ?? [], + 'beforeSurveyBarRender' => $beforeSurveyBarRender ?? [] ), false, false diff --git a/application/views/admin/survey/topbar/survey_topbar.php b/application/views/admin/survey/topbar/survey_topbar.php index 0c2f4b3fdc9..2860a018b1f 100644 --- a/application/views/admin/survey/topbar/survey_topbar.php +++ b/application/views/admin/survey/topbar/survey_topbar.php @@ -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',