24
24
use mod_bigbluebuttonbn \local \extension \mod_instance_helper ;
25
25
use stdClass ;
26
26
use core_plugin_manager ;
27
+ use core_component ;
27
28
28
29
/**
29
30
* Generic subplugin management helper
@@ -80,8 +81,7 @@ public static function action_url_addons(
80
81
*/
81
82
protected static function get_instances_implementing (string $ classname , ?array $ newparameters = []): array {
82
83
$ classes = self ::get_classes_implementing ($ classname );
83
- sort ($ classes ); // Make sure all extension classes are returned in the same order. This is arbitrarily in
84
- // alphabetical order and depends on the classname but this one way to ensure consistency across calls.
84
+ ksort ($ classes ); // Make sure all extension classes are returned in the correct order.
85
85
return array_map (function ($ targetclassname ) use ($ newparameters ) {
86
86
// If $newparameters is null, the constructor will be called without parameters.
87
87
return new $ targetclassname (...$ newparameters );
@@ -100,6 +100,9 @@ protected static function get_classes_implementing(string $classname): array {
100
100
$ classbasename = end ($ classnamecomponents );
101
101
$ allsubs = core_plugin_manager::instance ()->get_plugins_of_type (self ::BBB_EXTENSION_PLUGIN_NAME );
102
102
$ extensionclasses = [];
103
+ $ names = core_component::get_plugin_list (self ::BBB_EXTENSION_PLUGIN_NAME );
104
+ $ sortedlist = self ::get_sorted_plugins_list ($ names ); // Make sure to use the most updated list.
105
+ $ sortedlist = array_flip ($ sortedlist );
103
106
foreach ($ allsubs as $ sub ) {
104
107
if (!$ sub ->is_enabled ()) {
105
108
continue ;
@@ -112,11 +115,38 @@ protected static function get_classes_implementing(string $classname): array {
112
115
debugging ("The class $ targetclassname should extend $ classname in the subplugin {$ sub ->name }. Ignoring. " );
113
116
continue ;
114
117
}
115
- $ extensionclasses [] = $ targetclassname ;
118
+ if (!isset ($ sortedlist [$ sub ->name ])) {
119
+ debugging ("The class $ targetclassname does not belong to an existing subplugin. Ignoring " );
120
+ continue ;
121
+ }
122
+ // Return all extension classes based on subplugin order on manage extension page.
123
+ $ sortorder = $ sortedlist [$ sub ->name ];
124
+ $ extensionclasses [$ sortorder ] = $ targetclassname ;
116
125
}
117
126
return $ extensionclasses ;
118
127
}
119
128
129
+ /**
130
+ * Return plugin list sorted according to order from admin extension manager.
131
+ * @param array $names Array of plugin names
132
+ * @return array The sorted list of plugins
133
+ */
134
+ public static function get_sorted_plugins_list (array $ names ): array {
135
+ $ result = [];
136
+ foreach ($ names as $ name => $ path ) {
137
+ $ idx = get_config (self ::BBB_EXTENSION_PLUGIN_NAME . '_ ' . $ name , 'sortorder ' );
138
+ if (!$ idx ) {
139
+ $ idx = 0 ;
140
+ }
141
+ while (array_key_exists ($ idx , $ result )) {
142
+ $ idx += 1 ;
143
+ }
144
+ $ result [$ idx ] = $ name ;
145
+ }
146
+ ksort ($ result );
147
+ return $ result ;
148
+ }
149
+
120
150
/**
121
151
* Get all custom_completion addons classes.
122
152
*
0 commit comments