MDL-72413 url: Use the common module for setting the header

This commit is contained in:
Peter Dias 2021-09-22 10:58:03 +08:00
parent 3700cc6e25
commit 7fa1354496
4 changed files with 79 additions and 52 deletions

59
mod/url/deprecatedlib.php Normal file
View File

@ -0,0 +1,59 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of deprecated mod_url functions.
*
* @package mod_url
* @copyright 2021 Peter D
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Print url heading.
*
* @deprecated since 4.0
* @param object $url
* @param object $cm
* @param object $course
* @param bool $notused This variable is no longer used.
* @return void
*/
function url_print_heading($url, $cm, $course, $notused = false) {
global $OUTPUT;
debugging('url_print_heading is deprecated. Handled by activity_header now.', DEBUG_DEVELOPER);
echo $OUTPUT->heading(format_string($url->name), 2);
}
/**
* Print url introduction.
*
* @deprecated since 4.0
* @param object $url
* @param object $cm
* @param object $course
* @param bool $ignoresettings print even if not specified in modedit
* @return void
*/
function url_print_intro($url, $cm, $course, $ignoresettings=false) {
global $OUTPUT;
debugging('url_print_intro is deprecated. Handled by activity_header now.', DEBUG_DEVELOPER);
if ($intro = url_get_intro($url, $cm, $ignoresettings)) {
echo $OUTPUT->box_start('mod_introbox', 'urlintro');
echo $intro;
echo $OUTPUT->box_end();
}
}

View File

@ -172,37 +172,22 @@ function url_print_header($url, $cm, $course) {
}
/**
* Print url heading.
* Get url introduction.
*
* @param object $url
* @param object $cm
* @param object $course
* @param bool $notused This variable is no longer used.
* @return void
*/
function url_print_heading($url, $cm, $course, $notused = false) {
global $OUTPUT;
echo $OUTPUT->heading(format_string($url->name), 2);
}
/**
* Print url introduction.
* @param object $url
* @param object $cm
* @param object $course
* @param bool $ignoresettings print even if not specified in modedit
* @return void
* @return string
*/
function url_print_intro($url, $cm, $course, $ignoresettings=false) {
global $OUTPUT;
function url_get_intro(object $url, object $cm, bool $ignoresettings = false): string {
$options = empty($url->displayoptions) ? [] : (array) unserialize_array($url->displayoptions);
if ($ignoresettings or !empty($options['printintro'])) {
if (trim(strip_tags($url->intro))) {
echo $OUTPUT->box_start('mod_introbox', 'urlintro');
echo format_module_intro('url', $url, $cm->id);
echo $OUTPUT->box_end();
return format_module_intro('url', $url, $cm->id);
}
}
return '';
}
/**
@ -219,9 +204,11 @@ function url_display_frame($url, $cm, $course) {
if ($frame === 'top') {
$PAGE->set_pagelayout('frametop');
$PAGE->activityheader->set_attrs([
'description' => url_get_intro($url, $cm),
'title' => format_string($url->name)
]);
url_print_header($url, $cm, $course);
url_print_heading($url, $cm, $course);
url_print_intro($url, $cm, $course);
echo $OUTPUT->footer();
die;
@ -268,20 +255,9 @@ EOF;
function url_print_workaround($url, $cm, $course) {
global $OUTPUT, $PAGE, $USER;
$PAGE->activityheader->set_description(url_get_intro($url, $cm, true));
url_print_header($url, $cm, $course);
if (!$PAGE->has_secondary_navigation()) {
url_print_heading($url, $cm, $course, true);
}
// Display any activity information (eg completion requirements / dates).
$cminfo = cm_info::create($cm);
$completiondetails = \core_completion\cm_completion_details::get_instance($cminfo, $USER->id);
$activitydates = \core\activity_dates::get_dates_for_module($cminfo, $USER->id);
echo $OUTPUT->activity_information($cminfo, $completiondetails, $activitydates);
url_print_intro($url, $cm, $course, true);
$fullurl = url_get_full_url($url, $cm, $course);
$display = url_get_final_display_type($url);
@ -316,7 +292,7 @@ function url_print_workaround($url, $cm, $course) {
* @return does not return
*/
function url_display_embed($url, $cm, $course) {
global $PAGE, $OUTPUT, $USER;
global $PAGE, $OUTPUT;
$mimetype = resourcelib_guess_url_mimetype($url->externalurl);
$fullurl = url_get_full_url($url, $cm, $course);
@ -346,21 +322,11 @@ function url_display_embed($url, $cm, $course) {
$code = resourcelib_embed_general($fullurl, $title, $clicktoopen, $mimetype);
}
$PAGE->activityheader->set_description(url_get_intro($url, $cm));
url_print_header($url, $cm, $course);
if (!$PAGE->has_secondary_navigation()) {
url_print_heading($url, $cm, $course);
}
// Display any activity information (eg completion requirements / dates).
$cminfo = cm_info::create($cm);
$completiondetails = \core_completion\cm_completion_details::get_instance($cminfo, $USER->id);
$activitydates = \core\activity_dates::get_dates_for_module($cminfo, $USER->id);
echo $OUTPUT->activity_information($cminfo, $completiondetails, $activitydates);
echo $code;
url_print_intro($url, $cm, $course);
echo $OUTPUT->footer();
die;
}

5
mod/url/upgrade.txt Normal file
View File

@ -0,0 +1,5 @@
This files describes API changes in the quiz code.
=== 4.0 ===
* Functions url_print_heading and url_print_intro have been deprecated in favour for the activity header.

View File

@ -57,11 +57,8 @@ $PAGE->set_url('/mod/url/view.php', array('id' => $cm->id));
// Do not use PARAM_URL here, it is too strict and does not support general URIs!
$exturl = trim($url->externalurl);
if (empty($exturl) or $exturl === 'http://') {
$PAGE->activityheader->set_description(url_get_intro($url, $cm));
url_print_header($url, $cm, $course);
if (!$PAGE->has_secondary_navigation()) {
url_print_heading($url, $cm, $course);
}
url_print_intro($url, $cm, $course);
notice(get_string('invalidstoredurl', 'url'), new moodle_url('/course/view.php', array('id'=>$cm->course)));
die;
}