diff --git a/course/lib.php b/course/lib.php
index 38058dc..94017d0 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -1931,8 +1931,7 @@ 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()) {
+        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'));
@@ -1962,7 +1961,6 @@ function get_module_metadata($course, $modnames, $sectionreturn = null) {
                     $group->types[] = $subtype;
                 }
                 $modlist[$course->id][$modname] = $group;
-            }
         } else {
             $module = new stdClass();
             $module->title = get_string('modulename', $modname);
