From 39a9ac4098362f00debc849fc3e16a24267a50db Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Thu, 1 Dec 2016 12:45:49 +0800 Subject: [PATCH] MDL-57101 core_media: Only instantiate enabled plugins --- media/classes/manager.php | 33 ++++----------------------------- media/classes/player.php | 11 ----------- 2 files changed, 4 insertions(+), 40 deletions(-) diff --git a/media/classes/manager.php b/media/classes/manager.php index e502d5f7bea..84b4adb9fe9 100644 --- a/media/classes/manager.php +++ b/media/classes/manager.php @@ -142,44 +142,19 @@ class core_media_manager { protected function get_players() { // Save time by only building the list once. if (!$this->players) { - // Get raw list of players. - $allplayers = $this->get_players_raw(); $sortorder = \core\plugininfo\media::get_enabled_plugins(); $this->players = []; - foreach ($sortorder as $key) { - if (array_key_exists($key, $allplayers)) { - $this->players[] = $allplayers[$key]; + foreach ($sortorder as $name) { + $classname = "media_" . $name . "_plugin"; + if (class_exists($classname)) { + $this->players[] = new $classname(); } } } return $this->players; } - /** - * Obtains a raw list of player objects that includes objects regardless - * of whether they are disabled or not, and without sorting. - * - * You can override this in a subclass if you need to add additional_ - * players. - * - * The return array is be indexed by player name to make it easier to - * remove players in a subclass. - * - * @return array $players Array of core_media_player objects in any order - */ - protected function get_players_raw() { - $plugins = core_plugin_manager::instance()->get_plugins_of_type('media'); - $rv = []; - foreach ($plugins as $name => $dir) { - $classname = "media_" . $name . "_plugin"; - if (class_exists($classname)) { - $rv[$name] = new $classname(); - } - } - return $rv; - } - /** * Renders a media file (audio or video) using suitable embedded player. * diff --git a/media/classes/player.php b/media/classes/player.php index 55cd8e35dd9..cb05f1260ed 100644 --- a/media/classes/player.php +++ b/media/classes/player.php @@ -30,17 +30,6 @@ defined('MOODLE_INTERNAL') || die(); * Media players return embed HTML for a particular way of playing back audio * or video (or another file type). * - * In order to make the code more lightweight, this is not a plugin type - * (players cannot have their own settings, database tables, capabilities, etc). - * These classes are used only by core_media_renderer in outputrenderers.php. - * If you add a new class here (in core code) you must modify the - * get_players_raw function in that file to include it. - * - * If a Moodle installation wishes to add extra player objects they can do so - * by overriding that renderer in theme, and overriding the get_players_raw - * function. The new player class should then of course be defined within the - * custom theme or other suitable location, not in this file. - * * @package core_media * @copyright 2016 Marina Glancy * @author 2011 The Open University