Commit 1abd4376 authored by John Okely's avatar John Okely Committed by Marina Glancy
Browse files

MDL-57316 media: Setup media plugins in media_manager::instance()

parent c2e00335
......@@ -57,8 +57,8 @@ class filter_mediaplugin extends moodle_text_filter {
}
$jsinitialised = true;
$mediamanager = core_media_manager::instance();
$mediamanager->setup($page);
// Set up the media manager so that media plugins requiring JS are initialised.
$mediamanager = core_media_manager::instance($page);
}
public function filter($text, array $options = array()) {
......
......@@ -40,7 +40,7 @@ $PAGE->add_body_class('core_media_preview');
echo $OUTPUT->header();
$mediarenderer = core_media_manager::instance();
$mediarenderer = core_media_manager::instance($PAGE);
if (isloggedin() and !isguestuser() and $mediarenderer->can_embed_url($url)) {
require_sesskey();
......
......@@ -517,4 +517,11 @@ class core_media_manager_test extends core_media_manager {
}
return $out;
}
/**
* Override the constructor to access it.
*/
public function __construct() {
parent::__construct();
}
}
......@@ -100,27 +100,55 @@ class core_media_manager {
/**
* Returns a singleton instance of a manager
*
* Note as of Moodle 3.3, this will call setup for you.
*
* @return core_media_manager
*/
public static function instance() {
public static function instance($page = null) {
if (self::$instance === null) {
self::$instance = new self();
self::$instance = new self($page);
}
return self::$instance;
}
/**
* Construct a new core_media_manager instance
*
* @param moodle_page $page The page we are going to add requirements to.
* @see core_media_manager::instance()
*/
protected function __construct($page = null) {
// Use the passed $page if given, otherwise the $PAGE global.
if ($page == null) {
global $PAGE;
if (isset($PAGE)) {
$page = $PAGE;
}
}
if ($page) {
$players = $this->get_players();
foreach ($players as $player) {
$player->setup($page);
}
} else {
debugging('Could not determine the $PAGE. Media plugins will not be set up', DEBUG_DEVELOPER);
}
}
/**
* Setup page requirements.
*
* This should must only be called once per page request.
*
* @deprecated Moodle 3.3, The setup is now done in ::instance() so there is no need to call this
* @param moodle_page $page The page we are going to add requirements to.
* @see core_media_manager::instance()
* @todo MDL-57632 final deprecation
*/
public function setup($page) {
$players = $this->get_players();
foreach ($players as $player) {
$player->setup($page);
}
debugging('core_media_manager::setup() is deprecated.' .
'You only need to call core_media_manager::instance() now', DEBUG_DEVELOPER);
// No need to call ::instance from here, because the instance has already be set up.
}
/**
......
This files describes API changes in /media/ plugins,
information provided here is intended especially for developers.
=== 3.3 ===
* core_media_manager setup() is now deprecated as it is now called when initialising core_media_manager::instance().
......@@ -618,7 +618,7 @@ function lesson_get_media_html($lesson, $context) {
$extension = resourcelib_get_extension($url->out(false));
$mediamanager = core_media_manager::instance();
$mediamanager = core_media_manager::instance($PAGE);
$embedoptions = array(
core_media_manager::OPTION_TRUSTED => true,
core_media_manager::OPTION_BLOCK => true
......
......@@ -75,7 +75,7 @@ function resource_display_embed($resource, $cm, $course, $file) {
$extension = resourcelib_get_extension($file->get_filename());
$mediamanager = core_media_manager::instance();
$mediamanager = core_media_manager::instance($PAGE);
$embedoptions = array(
core_media_manager::OPTION_TRUSTED => true,
core_media_manager::OPTION_BLOCK => true,
......
......@@ -305,7 +305,7 @@ function url_display_embed($url, $cm, $course) {
$extension = resourcelib_get_extension($url->externalurl);
$mediamanager = core_media_manager::instance();
$mediamanager = core_media_manager::instance($PAGE);
$embedoptions = array(
core_media_manager::OPTION_TRUSTED => true,
core_media_manager::OPTION_BLOCK => true
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment