mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-57101 core_media: Only instantiate enabled plugins
This commit is contained in:
parent
8f5de6f268
commit
39a9ac4098
2 changed files with 4 additions and 40 deletions
|
@ -142,44 +142,19 @@ class core_media_manager {
|
||||||
protected function get_players() {
|
protected function get_players() {
|
||||||
// Save time by only building the list once.
|
// Save time by only building the list once.
|
||||||
if (!$this->players) {
|
if (!$this->players) {
|
||||||
// Get raw list of players.
|
|
||||||
$allplayers = $this->get_players_raw();
|
|
||||||
$sortorder = \core\plugininfo\media::get_enabled_plugins();
|
$sortorder = \core\plugininfo\media::get_enabled_plugins();
|
||||||
|
|
||||||
$this->players = [];
|
$this->players = [];
|
||||||
foreach ($sortorder as $key) {
|
foreach ($sortorder as $name) {
|
||||||
if (array_key_exists($key, $allplayers)) {
|
$classname = "media_" . $name . "_plugin";
|
||||||
$this->players[] = $allplayers[$key];
|
if (class_exists($classname)) {
|
||||||
|
$this->players[] = new $classname();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->players;
|
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.
|
* 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
|
* Media players return embed HTML for a particular way of playing back audio
|
||||||
* or video (or another file type).
|
* 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
|
* @package core_media
|
||||||
* @copyright 2016 Marina Glancy
|
* @copyright 2016 Marina Glancy
|
||||||
* @author 2011 The Open University
|
* @author 2011 The Open University
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue