MDL-57101 core_media: Only instantiate enabled plugins

This commit is contained in:
Frederic Massart 2016-12-01 12:45:49 +08:00
parent 8f5de6f268
commit 39a9ac4098
No known key found for this signature in database
GPG Key ID: AC343CE142B12FB9
2 changed files with 4 additions and 40 deletions

View File

@ -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.
*

View File

@ -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