Skip to content
Snippets Groups Projects
Commit 65e8a124 authored by Elmar Ludwig's avatar Elmar Ludwig
Browse files

don't create plugin instances from navigation context, fixes #4317

Closes #4317

Merge request studip/studip!3218
parent ee67801a
No related branches found
No related tags found
No related merge requests found
...@@ -47,60 +47,49 @@ class CourseNavigation extends Navigation ...@@ -47,60 +47,49 @@ class CourseNavigation extends Navigation
} }
/** /**
* Initialize the subnavigation of this item. This method * Add an array of navigation items to the subnavigation of this
* is called once before the first item is added or removed. * object. The new items are inserted at the appropriate position
* for this tool according to the order defined in tools_activated.
*
* @param int $plugin_id id of the module
* @param array $navigations navigation items to add
*/ */
public function initSubNavigation() public function addToolNavigation($plugin_id, array $navigations)
{ {
parent::initSubNavigation(); $found = null;
$where = null;
$admin_plugin_ids = []; foreach ($this->range->tools as $tool) {
$core_admin = PluginManager::getInstance()->getPlugin(CoreAdmin::class);
if ($core_admin) {
$admin_plugin_ids[] = $core_admin->getPluginId();
}
$core_studygroup_admin = PluginManager::getInstance()->getPlugin(CoreStudygroupAdmin::class);
if ($core_studygroup_admin) {
$admin_plugin_ids[] = $core_studygroup_admin->getPluginId();
}
$tools = $this->range->tools->getArrayCopy();
usort($tools, function ($a, $b) use ($admin_plugin_ids) {
if (in_array($a['plugin_id'], $admin_plugin_ids)) {
return -1;
}
if (in_array($b['plugin_id'], $admin_plugin_ids)) {
return 1;
}
return $a['position'] - $b['position'];
});
foreach ($tools as $tool) {
if ( if (
!($this->range instanceof Institute) $found
&& !Seminar_Perm::get()->have_studip_perm($tool->getVisibilityPermission(), $this->range->id) && $tool->metadata['navigation']
&& $tool->metadata['navigation'] !== 'admin'
) { ) {
continue; $where = $tool->metadata['navigation'];
break;
} }
$studip_module = $tool->getStudipModule(); if ($tool->plugin_id == $plugin_id) {
if (!($studip_module instanceof StudipModule)) { $tool->metadata['navigation'] = key($navigations);
continue; $found = $tool;
} }
}
$tool_nav = $studip_module->getTabNavigation($this->range->id) ?: []; // always insert admin module in first position
if (key($navigations) === 'admin') {
$where = key($this->subnav);
}
foreach ($tool_nav as $nav_name => $navigation) { foreach ($navigations as $key => $nav) {
if (!$nav_name || !$navigation instanceof Navigation) { if (
continue; $this->range instanceof Institute
|| Seminar_Perm::get()->have_studip_perm($found->getVisibilityPermission(), $this->range->id)
) {
if (isset($found->metadata['displayname'])) {
$nav->setTitle($found->getDisplayname());
} }
if ($tool->metadata['displayname']) { $this->insertSubNavigation($key, $nav, $where);
$navigation->setTitle($tool->getDisplayname());
}
$this->addSubNavigation($nav_name, $navigation);
} }
} }
} }
......
...@@ -44,8 +44,16 @@ class PluginEngine ...@@ -44,8 +44,16 @@ class PluginEngine
// load course plugins // load course plugins
if (Context::getId()) { if (Context::getId()) {
self::getPlugins(StudipModule::class); $modules = self::getPlugins(StudipModule::class, Context::getId());
self::getPlugins(StandardPlugin::class); $navigation = Navigation::getItem('/course');
foreach ($modules as $module) {
$tabs = $module->getTabNavigation(Context::getId());
if ($navigation && $tabs) {
$navigation->addToolNavigation($module->getPluginId(), $tabs);
}
}
} }
// load admin plugins // load admin plugins
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment