Skip to content

Commit

Permalink
Dev: Add a new event beforeAdminMenuRender
Browse files Browse the repository at this point in the history
Dev: Used as an extention point to add menus to top menu
Dev: Wiki information here:
Dev: https://manual.limesurvey.org/Extra_menus_event
Dev: I've made classes for the menus: ExtraMenu and
Dev: ExtraMenuItem. They are in my plugin, could be merged
Dev: into core at a later point to be used in other menu
Dev: extension points.
  • Loading branch information
olleharstedt committed Apr 25, 2016
1 parent 778916b commit c4276c9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
25 changes: 25 additions & 0 deletions application/core/Survey_Common_Action.php
Expand Up @@ -509,6 +509,9 @@ public function _showadminmenu()
$updateNotification = $updateModel->updateNotification;
$aData['showupdate'] = Yii::app()->getConfig('updatable') && $updateNotification->result && ! $updateNotification->unstable_update ;

// Fetch extra menus from plugins, e.g. last visited surveys
$aData['extraMenus'] = $this->fetchExtraMenus($aData);

$this->getController()->renderPartial("/admin/super/adminmenu", $aData);
}
}
Expand Down Expand Up @@ -1377,4 +1380,26 @@ protected function _tempdir($dir, $prefix='', $mode=0700)
return $path;
}

/**
* Get extra menus from plugins that are using event beforeAdminMenuRender
*
* @param array $aData
* @return array<ExtraMenu>
*/
protected function fetchExtraMenus(array $aData)
{
$event = new PluginEvent('beforeAdminMenuRender', $this);
$event->set('data', $aData);
$result = App()->getPluginManager()->dispatchEvent($event);

$extraMenus = $result->get('extraMenus');

if ($extraMenus === null)
{
$extraMenus = array();
}

return $extraMenus;
}

}
23 changes: 23 additions & 0 deletions application/views/admin/super/adminmenu.php
Expand Up @@ -140,6 +140,29 @@
</li>
<?php endif;?>

<!-- Extra menus from plugins -->
<?php // TODO: This views should be in same module as ExtraMenu and ExtraMenuItem classes (not plugin) ?>
<?php foreach ($extraMenus as $menu): ?>
<li class="dropdown">
<?php if ($menu->isDropDown()): ?>
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php echo $menu->getLabel(); ?>&nbsp;<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<?php foreach ($menu->getMenuItems() as $menuItem): ?>
<?php if ($menuItem->isDivider()): ?>
<li class="divider"></li>
<?php else: ?>
<li>
<a href="<?php echo $menuItem->getHref(); ?>"><?php echo $menuItem->getLabel(); ?></a>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php else: ?>
<a href="<?php echo $menu->getHref(); ?>"><?php echo $menu->getLabel(); ?></a>
<?php endif; ?>
</li>
<?php endforeach; ?>

<?php if($showupdate): ?>
<li class="">
<a href="#notifications">
Expand Down

0 comments on commit c4276c9

Please sign in to comment.