Merge branch 'master' of https://github.com/tniessen/moodle
[moodle.git] / mod / book / lib.php
index 860db56..74b11af 100644 (file)
@@ -304,15 +304,10 @@ function book_supports($feature) {
 function book_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $booknode) {
     global $USER, $PAGE, $OUTPUT;
 
-    $plugins = core_component::get_plugin_list('booktool');
-    foreach ($plugins as $plugin => $dir) {
-        if (file_exists("$dir/lib.php")) {
-            require_once("$dir/lib.php");
-        }
-        $function = 'booktool_'.$plugin.'_extend_settings_navigation';
-        if (function_exists($function)) {
-            $function($settingsnav, $booknode);
-        }
+    if ($booknode->children->count() > 0) {
+        $firstkey = $booknode->children->get_key_list()[0];
+    } else {
+        $firstkey = null;
     }
 
     $params = $PAGE->url->params();
@@ -327,9 +322,21 @@ function book_extend_settings_navigation(settings_navigation $settingsnav, navig
             $edit = '1';
         }
         $url = new moodle_url('/mod/book/view.php', array('id'=>$params['id'], 'chapterid'=>$params['chapterid'], 'edit'=>$edit, 'sesskey'=>sesskey()));
-        $booknode->add($string, $url, navigation_node::TYPE_SETTING);
+        $editnode = navigation_node::create($string, $url, navigation_node::TYPE_SETTING);
+        $booknode->add_node($editnode, $firstkey);
         $PAGE->set_button($OUTPUT->single_button($url, $string));
     }
+
+    $plugins = core_component::get_plugin_list('booktool');
+    foreach ($plugins as $plugin => $dir) {
+        if (file_exists("$dir/lib.php")) {
+            require_once("$dir/lib.php");
+        }
+        $function = 'booktool_'.$plugin.'_extend_settings_navigation';
+        if (function_exists($function)) {
+            $function($settingsnav, $booknode);
+        }
+    }
 }