Merge branch 'MDL-81047-main' of https://github.com/andrewnicols/moodle into main

This commit is contained in:
Paul Holden 2024-03-11 12:18:05 +00:00
commit 3d97e8616c
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
6 changed files with 37 additions and 26 deletions

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_mobile\local\hooks\output;
namespace tool_mobile\local\hook\output;
/**
* Allows plugins to add any elements to the page <head> html tag
@ -23,14 +23,13 @@ namespace tool_mobile\local\hooks\output;
* @copyright 2023 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class standard_head_html_prepend {
class before_standard_head_html_generation {
/**
* Callback to add head elements.
*
* @param \core\hook\output\standard_head_html_prepend $hook
* @param \core\hook\output\before_standard_head_html_generation $hook
*/
public static function callback(\core\hook\output\standard_head_html_prepend $hook): void {
public static function callback(\core\hook\output\before_standard_head_html_generation $hook): void {
global $CFG, $PAGE;
// Smart App Banners meta tag is only displayed if mobile services are enabled and configured.
if (!empty($CFG->enablemobilewebservice)) {
@ -45,7 +44,7 @@ class standard_head_html_prepend {
if (!empty($mobilesettings->androidappid)) {
$mobilemanifesturl = "$CFG->wwwroot/$CFG->admin/tool/mobile/mobile.webmanifest.php";
$hook->add_html('<link rel="manifest" href="'.$mobilemanifesturl.'" />');
$hook->add_html('<link rel="manifest" href="' . $mobilemanifesturl . '" />');
}
}
}

View File

@ -26,8 +26,8 @@ defined('MOODLE_INTERNAL') || die();
$callbacks = [
[
'hook' => core\hook\output\standard_head_html_prepend::class,
'callback' => 'tool_mobile\local\hooks\output\standard_head_html_prepend::callback',
'hook' => core\hook\output\before_standard_head_html_generation::class,
'callback' => 'tool_mobile\local\hook\output\before_standard_head_html_generation::callback',
'priority' => 0,
],
];

View File

@ -23,7 +23,7 @@
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2023100900; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2024022600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2023100400; // Requires this Moodle version.
$plugin->component = 'tool_mobile'; // Full name of the plugin (used for diagnostics).
$plugin->dependencies = [

View File

@ -26,19 +26,25 @@ namespace core\hook\output;
#[\core\attribute\tags('output')]
#[\core\attribute\label('Allows plugins to add any elements to the page &lt;head&gt; html tag.')]
#[\core\attribute\hook\replaces_callbacks('before_standard_html_head')]
class standard_head_html_prepend {
/** @var string $output Stores results from callbacks */
private $output = '';
final class before_standard_head_html_generation {
public function __construct(
/** @var \renderer_base The core_renderer instnace used for the generation */
public readonly \renderer_base $renderer,
private string $output = '',
) {
}
/**
* Plugins implementing callback can add any HTML to the page.
*
* Must be a string containing valid html head content
*
* @param string $output
* @param null|string $output
*/
public function add_html(string $output): void {
$this->output .= $output;
public function add_html(?string $output): void {
if ($output) {
$this->output .= $output;
}
}
/**

View File

@ -35,6 +35,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use core\di;
use core\hook\manager as hook_manager;
use core\output\named_templatable;
use core_completion\cm_completion_details;
use core_course\output\activity_information;
@ -698,33 +700,37 @@ class core_renderer extends renderer_base {
$this->page->blocks->ensure_content_created($region, $this);
}
$output = '';
// Give plugins an opportunity to add any head elements. The callback
// must always return a string containing valid html head content.
$hook = new \core\hook\output\standard_head_html_prepend();
\core\hook\manager::get_instance()->dispatch($hook);
$hook = new \core\hook\output\before_standard_head_html_generation($this);
di::get(hook_manager::class)->dispatch($hook);
$hook->process_legacy_callbacks();
$output .= $hook->get_output();
// Allow a url_rewrite plugin to setup any dynamic head content.
if (isset($CFG->urlrewriteclass) && !isset($CFG->upgraderunning)) {
$class = $CFG->urlrewriteclass;
$output .= $class::html_head_setup();
$hook->add_html($class::html_head_setup());
}
$output .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . "\n";
$output .= '<meta name="keywords" content="moodle, ' . $this->page->title . '" />' . "\n";
$hook->add_html('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . "\n");
$hook->add_html('<meta name="keywords" content="moodle, ' . $this->page->title . '" />' . "\n");
// This is only set by the {@link redirect()} method
$output .= $this->metarefreshtag;
$hook->add_html($this->metarefreshtag);
// Check if a periodic refresh delay has been set and make sure we arn't
// already meta refreshing
if ($this->metarefreshtag=='' && $this->page->periodicrefreshdelay!==null) {
$output .= '<meta http-equiv="refresh" content="'.$this->page->periodicrefreshdelay.';url='.$this->page->url->out().'" />';
$hook->add_html(
html_writer::empty_tag('meta', [
'http-equiv' => 'refresh',
'content' => $this->page->periodicrefreshdelay . ';url='.$this->page->url->out(),
]),
);
}
$output = $hook->get_output();
// Set up help link popups for all links with the helptooltip class
$this->page->requires->js_init_call('M.util.help_popups.setup');

View File

@ -37,7 +37,7 @@ information provided here is intended especially for developers.
- get_attempts_available(): Used to get the number of attempts available for the task.
* There is a new DML method $DB->get_fieldset. For some reason, this did not exist even though get_fieldset_select etc. did.
* The following callbacks have been migrated to hooks:
- before_standard_html_head() -> core\hook\output\standard_head_html_prepend
- before_standard_html_head() -> core\hook\output\before_standard_head_html_generation
* Deprecated PARAM_ types with the exception of PARAM_CLEAN now emit a deprecation exception. These were all deprecated in Moodle 2.0.
* A new \core\deprecated attribute can be used to more clearly describe deprecated methods.
* A new \core\deprecation class can be used to inspect for deprecated attributes: