mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-57101 core_media: Only instantiate enabled plugins
This commit is contained in:
parent
8f5de6f268
commit
39a9ac4098
@ -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.
|
||||
*
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user