MDL-39087 Fix plugin_manager::plugin_name() implementation
authorDavid Mudrák <david@moodle.com>
Thu, 11 Apr 2013 12:20:22 +0000 (14:20 +0200)
committerDavid Mudrák <david@moodle.com>
Thu, 11 Apr 2013 23:42:58 +0000 (01:42 +0200)
This is not directly related to the issue. However, it turned out that
if this method was called on plugin_manager without loaded plugins, it
would throw an error. This new implementation uses cleaner access to the
plugininfo subclass.

lib/pluginlib.php

index 6955744..d833242 100644 (file)
@@ -221,12 +221,18 @@ class plugin_manager {
     /**
      * Returns a localized name of a given plugin
      *
-     * @param string $plugin name of the plugin, eg mod_workshop or auth_ldap
+     * @param string $component name of the plugin, eg mod_workshop or auth_ldap
      * @return string
      */
-    public function plugin_name($plugin) {
-        list($type, $name) = normalize_component($plugin);
-        return $this->pluginsinfo[$type][$name]->displayname;
+    public function plugin_name($component) {
+
+        $pluginfo = $this->get_plugin_info($component);
+
+        if (is_null($pluginfo)) {
+            throw new moodle_exception('err_unknown_plugin', 'core_plugin', '', array('plugin' => $component));
+        }
+
+        return $pluginfo->displayname;
     }
 
     /**