From 7fa13544964673ff244a80f1bb960dd389eb985c Mon Sep 17 00:00:00 2001 From: Peter Dias Date: Wed, 22 Sep 2021 10:58:03 +0800 Subject: [PATCH] MDL-72413 url: Use the common module for setting the header --- mod/url/deprecatedlib.php | 59 +++++++++++++++++++++++++++++++++++++ mod/url/locallib.php | 62 +++++++++------------------------------ mod/url/upgrade.txt | 5 ++++ mod/url/view.php | 5 +--- 4 files changed, 79 insertions(+), 52 deletions(-) create mode 100644 mod/url/deprecatedlib.php create mode 100644 mod/url/upgrade.txt diff --git a/mod/url/deprecatedlib.php b/mod/url/deprecatedlib.php new file mode 100644 index 00000000000..87530d7f9fd --- /dev/null +++ b/mod/url/deprecatedlib.php @@ -0,0 +1,59 @@ +. + +/** + * 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(); + } +} diff --git a/mod/url/locallib.php b/mod/url/locallib.php index 7aca2eb4c59..1144202faa9 100644 --- a/mod/url/locallib.php +++ b/mod/url/locallib.php @@ -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; } diff --git a/mod/url/upgrade.txt b/mod/url/upgrade.txt new file mode 100644 index 00000000000..cbc598a736d --- /dev/null +++ b/mod/url/upgrade.txt @@ -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. \ No newline at end of file diff --git a/mod/url/view.php b/mod/url/view.php index 1068a6e5545..00119759a57 100644 --- a/mod/url/view.php +++ b/mod/url/view.php @@ -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; }