MDL-73726 dataformat: obey sort order when returning enabled plugins.
This commit is contained in:
@@ -47,6 +47,25 @@ class dataformat extends base {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a list of dataformat types, return them sorted according to site configuration (if set)
|
||||
*
|
||||
* @param string[] $formats List of formats, ['csv', 'pdf', etc]
|
||||
* @return string[] List of formats according to configured sort, ['csv', 'odf', etc]
|
||||
*/
|
||||
private static function get_plugins_sortorder(array $formats): array {
|
||||
global $CFG;
|
||||
|
||||
if (!empty($CFG->dataformat_plugins_sortorder)) {
|
||||
$order = explode(',', $CFG->dataformat_plugins_sortorder);
|
||||
$order = array_merge(array_intersect($order, $formats), array_diff($formats, $order));
|
||||
} else {
|
||||
$order = $formats;
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gathers and returns the information about all plugins of the given type
|
||||
*
|
||||
@@ -57,16 +76,9 @@ class dataformat extends base {
|
||||
* @return array of plugintype classes, indexed by the plugin name
|
||||
*/
|
||||
public static function get_plugins($type, $typerootdir, $typeclass, $pluginman) {
|
||||
global $CFG;
|
||||
$formats = parent::get_plugins($type, $typerootdir, $typeclass, $pluginman);
|
||||
|
||||
if (!empty($CFG->dataformat_plugins_sortorder)) {
|
||||
$order = explode(',', $CFG->dataformat_plugins_sortorder);
|
||||
$order = array_merge(array_intersect($order, array_keys($formats)),
|
||||
array_diff(array_keys($formats), $order));
|
||||
} else {
|
||||
$order = array_keys($formats);
|
||||
}
|
||||
$order = static::get_plugins_sortorder(array_keys($formats));
|
||||
$sortedformats = array();
|
||||
foreach ($order as $formatname) {
|
||||
$sortedformats[$formatname] = $formats[$formatname];
|
||||
@@ -79,18 +91,17 @@ class dataformat extends base {
|
||||
* @return array|null of enabled plugins $pluginname=>$pluginname, null means unknown
|
||||
*/
|
||||
public static function get_enabled_plugins() {
|
||||
$enabled = array();
|
||||
$plugins = core_plugin_manager::instance()->get_installed_plugins('dataformat');
|
||||
|
||||
if (!$plugins) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$order = static::get_plugins_sortorder(array_keys($plugins));
|
||||
$enabled = array();
|
||||
foreach ($plugins as $plugin => $version) {
|
||||
$disabled = get_config('dataformat_' . $plugin, 'disabled');
|
||||
foreach ($order as $formatname) {
|
||||
$disabled = get_config('dataformat_' . $formatname, 'disabled');
|
||||
if (empty($disabled)) {
|
||||
$enabled[$plugin] = $plugin;
|
||||
$enabled[$formatname] = $formatname;
|
||||
}
|
||||
}
|
||||
return $enabled;
|
||||
|
||||
Reference in New Issue
Block a user