From b8efcb9233b5d4527bfc2c2bfaf8d9d5d8e6ebbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Sat, 16 Mar 2013 02:07:34 +0100 Subject: [PATCH] MDL-38509 Implement new plugin_manager::plugintype_name() This has exactly the same behaviour as the existing plugintype_name_plural() method, but returns the singular form of the plugin type (such as 'Activity module'). --- lib/pluginlib.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/pluginlib.php b/lib/pluginlib.php index f0f93f7d4a2..dc925792a6e 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -229,6 +229,35 @@ class plugin_manager { return $this->pluginsinfo[$type][$name]->displayname; } + /** + * Returns a localized name of a plugin typed in singular form + * + * Most plugin types define their names in core_plugin lang file. In case of subplugins, + * we try to ask the parent plugin for the name. In the worst case, we will return + * the value of the passed $type parameter. + * + * @param string $type the type of the plugin, e.g. mod or workshopform + * @return string + */ + public function plugintype_name($type) { + + if (get_string_manager()->string_exists('type_' . $type, 'core_plugin')) { + // for most plugin types, their names are defined in core_plugin lang file + return get_string('type_' . $type, 'core_plugin'); + + } else if ($parent = $this->get_parent_of_subplugin($type)) { + // if this is a subplugin, try to ask the parent plugin for the name + if (get_string_manager()->string_exists('subplugintype_' . $type, $parent)) { + return $this->plugin_name($parent) . ' / ' . get_string('subplugintype_' . $type, $parent); + } else { + return $this->plugin_name($parent) . ' / ' . $type; + } + + } else { + return $type; + } + } + /** * Returns a localized name of a plugin type in plural form *