diff --git a/course/lib.php b/course/lib.php
index 38058dc..94017d0 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -600,7 +600,7 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
         $firstField = format_string($courses[$log->course], true, array('context' => $coursecontext));
         $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
         $row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info);
-        $actionurl = $CFG->wwwroot. make_log_url($log->module,$log->url);
+        $actionurl = $CFG->wwwroot. make_log_url($log->module,$log->url);
         $row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action.' ('.$actionurl.')', $log->info);
         $text = implode("\t", $row);
         echo $text." \n";
@@ -1931,38 +1931,36 @@ function get_module_metadata($course, $modnames, $sectionreturn = null) {
 
         // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
         $gettypesfunc =  $modname.'_get_types';
-        if (function_exists($gettypesfunc)) {
-            if ($types = $gettypesfunc()) {
-                $group = new stdClass();
-                $group->name = $modname;
-                $group->icon = $OUTPUT->pix_icon('icon', '', $modname, array('class' => 'icon'));
-                foreach($types as $type) {
-                    if ($type->typestr === '--') {
-                        continue;
-                    }
-                    if (strpos($type->typestr, '--') === 0) {
-                        $group->title = str_replace('--', '', $type->typestr);
-                        continue;
-                    }
-                    // Set the Sub Type metadata
-                    $subtype = new stdClass();
-                    $subtype->title = $type->typestr;
-                    $subtype->type = str_replace('&amp;', '&', $type->type);
-                    $subtype->name = preg_replace('/.*type=/', '', $subtype->type);
-                    $subtype->archetype = $type->modclass;
-
-                    // The group archetype should match the subtype archetypes and all subtypes
-                    // should have the same archetype
-                    $group->archetype = $subtype->archetype;
-
-                    if (get_string_manager()->string_exists('help' . $subtype->name, $modname)) {
-                        $subtype->help = get_string('help' . $subtype->name, $modname);
-                    }
-                    $subtype->link = $urlbase . $subtype->type;
-                    $group->types[] = $subtype;
+        if (function_exists($gettypesfunc) && ($types = $gettypesfunc()) && is_array($types) && count($types) > 0) {
+            $group = new stdClass();
+            $group->name = $modname;
+            $group->icon = $OUTPUT->pix_icon('icon', '', $modname, array('class' => 'icon'));
+            foreach($types as $type) {
+                if ($type->typestr === '--') {
+                    continue;
+                }
+                if (strpos($type->typestr, '--') === 0) {
+                    $group->title = str_replace('--', '', $type->typestr);
+                    continue;
+                }
+                // Set the Sub Type metadata
+                $subtype = new stdClass();
+                $subtype->title = $type->typestr;
+                $subtype->type = str_replace('&amp;', '&', $type->type);
+                $subtype->name = preg_replace('/.*type=/', '', $subtype->type);
+                $subtype->archetype = $type->modclass;
+
+                // The group archetype should match the subtype archetypes and all subtypes
+                // should have the same archetype
+                $group->archetype = $subtype->archetype;
+
+                if (get_string_manager()->string_exists('help' . $subtype->name, $modname)) {
+                    $subtype->help = get_string('help' . $subtype->name, $modname);
                 }
-                $modlist[$course->id][$modname] = $group;
+                $subtype->link = $urlbase . $subtype->type;
+                $group->types[] = $subtype;
             }
+            $modlist[$course->id][$modname] = $group;
         } else {
             $module = new stdClass();
             $module->title = get_string('modulename', $modname);
