Skip to content

Commit

Permalink
MDL-83766 mod_bigbluebuttonbn: Add subplugin sort
Browse files Browse the repository at this point in the history
* Change sort from default alphabetical to order in manage extension list order
  • Loading branch information
ssj365 committed Nov 22, 2024
1 parent 269a8a8 commit 197461d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 11 additions & 3 deletions mod/bigbluebuttonbn/classes/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use mod_bigbluebuttonbn\local\extension\custom_completion_addons;
use mod_bigbluebuttonbn\local\extension\mod_form_addons;
use mod_bigbluebuttonbn\local\extension\mod_instance_helper;
use mod_bigbluebuttonbn\local\plugins\admin_plugin_manager;
use stdClass;
use core_plugin_manager;

Expand Down Expand Up @@ -80,8 +81,7 @@ public static function action_url_addons(
*/
protected static function get_instances_implementing(string $classname, ?array $newparameters = []): array {
$classes = self::get_classes_implementing($classname);
sort($classes); // Make sure all extension classes are returned in the same order. This is arbitrarily in
// alphabetical order and depends on the classname but this one way to ensure consistency across calls.
ksort($classes); // Make sure all extension classes are returned in the correct order.
return array_map(function($targetclassname) use ($newparameters) {
// If $newparameters is null, the constructor will be called without parameters.
return new $targetclassname(...$newparameters);
Expand All @@ -100,6 +100,8 @@ protected static function get_classes_implementing(string $classname): array {
$classbasename = end($classnamecomponents);
$allsubs = core_plugin_manager::instance()->get_plugins_of_type(self::BBB_EXTENSION_PLUGIN_NAME);
$extensionclasses = [];
$sortedlist = admin_plugin_manager::get_sorted_plugins_list(); // Make sure to use the most updated list.
$sortedlist = array_flip($sortedlist);
foreach ($allsubs as $sub) {
if (!$sub->is_enabled()) {
continue;
Expand All @@ -112,7 +114,13 @@ protected static function get_classes_implementing(string $classname): array {
debugging("The class $targetclassname should extend $classname in the subplugin {$sub->name}. Ignoring.");
continue;
}
$extensionclasses[] = $targetclassname;
if (!isset($sortedlist[$sub->name])) {
debugging("The class $targetclassname does not belong to an existing subplugin. Ignoring");
continue;
}
// Return all extension classes based on subplugin order on manage extension page.
$sortorder = $sortedlist[$sub->name];
$extensionclasses[$sortorder] = $targetclassname;
}
return $extensionclasses;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function plugins_view(): void {
$table->set_attribute('class', 'admintable generaltable');
$table->setup();

$plugins = $this->get_sorted_plugins_list();
$plugins = admin_plugin_manager::get_sorted_plugins_list();
$instances = core_plugin_manager::instance()->get_plugins_of_type(extension::BBB_EXTENSION_PLUGIN_NAME);

foreach ($plugins as $idx => $plugin) {
Expand Down Expand Up @@ -189,7 +189,7 @@ private function print_header(): void {
*
* @return array The list of plugins
*/
public function get_sorted_plugins_list(): array {
public static function get_sorted_plugins_list(): array {
$names = core_component::get_plugin_list(extension::BBB_EXTENSION_PLUGIN_NAME);

$result = [];
Expand Down Expand Up @@ -299,7 +299,7 @@ private function plugins_movedown(string $plugintomove): string {
* @return string The next page to display
*/
private function move_plugin(string $plugintomove, string $dir): string {
$plugins = $this->get_sorted_plugins_list();
$plugins = admin_plugin_manager::get_sorted_plugins_list();
$plugins = array_values($plugins);
$currentindex = array_search($plugintomove, $plugins);
if ($currentindex === false) {
Expand Down

0 comments on commit 197461d

Please sign in to comment.