From bd9f73e23c39f46cf36d50cce20afa8a7cc34722 Mon Sep 17 00:00:00 2001 From: Alexander Bias Date: Sun, 13 Oct 2024 19:13:04 +0200 Subject: [PATCH] Upgrade: Adopt changes from MDL-82183 where lib/outputrenderers.php was split up + Upgrade: Remove legacy implementation of before_standard_html_head, resolves #606. --- CHANGES.md | 2 + UPGRADE.md | 3 +- classes/output/core_renderer.php | 153 ++++++++++++++++++++----------- 3 files changed, 102 insertions(+), 56 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 83b43eec9c9..92cb5da8747 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,8 @@ Changes ### Unreleased +* 2024-10-13 - Upgrade: Remove legacy implementation of before_standard_html_head, resolves #606. +* 2024-10-13 - Upgrade: Adopt changes from MDL-82183 where lib/outputrenderers.php was split up. * 2024-10-13 - Upgrade: Adopt changes from MDL-75671 in navbar.mustache * 2024-10-13 - Upgrade: Adopt changes from MDL-81725 in cm.mustache * 2024-10-13 - Upgrade: Adopt changes from MDL-75671 in cm.mustache diff --git a/UPGRADE.md b/UPGRADE.md index 50a67062847..d35084181b1 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -14,7 +14,8 @@ Upstream changes ---------------- * This theme is built on top of theme_boost from Moodle core. It inherits the codebase from theme_boost and overwrites and extends several behaviours and functions. Doing this, code duplication couldn't be avoided. If there are any upstream changes in theme_boost, you should check if they should be adopted to this theme as well. -* In addition to that, you should check any upstream changes which happen in /lib/templates and /lib/outputrenderers.php as some of these templates and renderers are overwritten in this theme as well. +* In addition to that, you should check any upstream changes which happen in /lib/templates, /lib/classes/output/core_renderer.php and /lib/classes/output/renderer_base.php as some of these templates and renderers are overwritten in this theme as well. +* In addition to that, you should check any occurences of 'copied and modified' in Boost Union as these comments might indicate additional places where you have to check upstream changes. * In addition to that, you should check if any additions to theme_boost_union_get_scss_to_mark_external_links() should be made. This might be particularly necessary if any new links have been added to the footer questionmark icon in Moodle core (have a look at footer.mustache) or if any links have been added which have a hardcoded external-link icon (check for new occurrences of "i/externallink" in the Moodle codebase). diff --git a/classes/output/core_renderer.php b/classes/output/core_renderer.php index 76c3e2d5e81..1e27f57cedc 100644 --- a/classes/output/core_renderer.php +++ b/classes/output/core_renderer.php @@ -23,14 +23,16 @@ */ namespace theme_boost_union\output; + use context_course; use context_system; -use core_userfeedback; use html_writer; use moodle_url; +use stdClass; use core\di; use core\hook\manager as hook_manager; use core\hook\output\before_standard_footer_html_generation; +use core_block\output\block_contents; /** * Extending the core_renderer interface. @@ -44,7 +46,7 @@ class core_renderer extends \theme_boost\output\core_renderer { /** * Returns the moodle_url for the favicon. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/core_renderer.php * * It checks if the favicon is overridden in a flavour and, if yes, it serves this favicon. * If there isn't a favicon in any flavour set, it serves the general favicon. @@ -84,8 +86,13 @@ public function favicon() { // Compose the URL to the flavour's favicon. $flavourfaviconurl = moodle_url::make_pluginfile_url( - context_system::instance()->id, 'theme_boost_union', 'flavours_look_favicon', $flavour->id, - '/'.theme_get_revision(), '/'.$flavour->look_favicon); + context_system::instance()->id, + 'theme_boost_union', + 'flavours_look_favicon', + $flavour->id, + '/'.theme_get_revision(), + '/'.$flavour->look_favicon + ); // Return the URL. return $flavourfaviconurl; @@ -108,14 +115,20 @@ public function favicon() { } // Use $CFG->themerev to prevent browser caching when the file changes. - return moodle_url::make_pluginfile_url(context_system::instance()->id, 'theme_boost_union', 'favicon', '64x64/', - theme_get_revision(), $logo); + return moodle_url::make_pluginfile_url( + context_system::instance()->id, + 'theme_boost_union', + 'favicon', + '64x64/', + theme_get_revision(), + $logo + ); } /** * Return the site's logo URL, if any. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/renderer_base.php * * It checks if the logo is overridden in a flavour and, if yes, it serves this logo. * If there isn't a logo in any flavour set, it serves the general logo. @@ -154,9 +167,14 @@ public function get_logo_url($maxwidth = null, $maxheight = 200) { $hasflavourlogo = true; // Compose the URL to the flavour's logo. - $flavourlogourl = moodle_url::make_pluginfile_url( - context_system::instance()->id, 'theme_boost_union', 'flavours_look_logo', $flavour->id, - '/'.theme_get_revision(), '/'.$flavour->look_logo); + $flavourlogourl = core\url::make_pluginfile_url( + context_system::instance()->id, + 'theme_boost_union', + 'flavours_look_logo', + $flavour->id, + '/'.theme_get_revision(), + '/'.$flavour->look_logo + ); // Return the URL. return $flavourlogourl; @@ -194,14 +212,20 @@ public function get_logo_url($maxwidth = null, $maxheight = 200) { } // Use $CFG->themerev to prevent browser caching when the file changes. - return moodle_url::make_pluginfile_url(context_system::instance()->id, 'theme_boost_union', 'logo', $filepath, - theme_get_revision(), $logo); + return moodle_url::make_pluginfile_url( + context_system::instance()->id, + 'theme_boost_union', + 'logo', + $filepath, + theme_get_revision(), + $logo + ); } /** * Return the site's compact logo URL, if any. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/renderer_base.php * * It checks if the logo is overridden in a flavour and, if yes, it serves this logo. * If there isn't a logo in any flavour set, it serves the general compact logo. @@ -240,9 +264,14 @@ public function get_compact_logo_url($maxwidth = 300, $maxheight = 300) { $hasflavourlogo = true; // Compose the URL to the flavour's compact logo. - $flavourlogourl = moodle_url::make_pluginfile_url( - context_system::instance()->id, 'theme_boost_union', 'flavours_look_logocompact', $flavour->id, - '/'.theme_get_revision(), '/'.$flavour->look_logocompact); + $flavourlogourl = core\url::make_pluginfile_url( + context_system::instance()->id, + 'theme_boost_union', + 'flavours_look_logocompact', + $flavour->id, + '/'.theme_get_revision(), + '/'.$flavour->look_logocompact + ); // Return the URL. return $flavourlogourl; @@ -277,14 +306,20 @@ public function get_compact_logo_url($maxwidth = 300, $maxheight = 300) { } // Use $CFG->themerev to prevent browser caching when the file changes. - return moodle_url::make_pluginfile_url(context_system::instance()->id, 'theme_boost_union', 'logocompact', $filepath, - theme_get_revision(), $logo); + return moodle_url::make_pluginfile_url( + context_system::instance()->id, + 'theme_boost_union', + 'logocompact', + $filepath, + theme_get_revision(), + $logo + ); } /** * Returns HTML attributes to use within the body tag. This includes an ID and classes. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/core_renderer.php * * @since Moodle 2.5.1 2.6 * @param string|array $additionalclasses Any additional classes to give the body tag, @@ -351,13 +386,13 @@ public function body_attributes($additionalclasses = []) { break; } - return ' id="'. $this->body_id().'" class="'.$this->body_css_classes($additionalclasses).'"'; + return ' id="' . $this->body_id() . '" class="' . $this->body_css_classes($additionalclasses) . '"'; } /** * Wrapper for header elements. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/core_renderer.php * * @return string HTML to display the main header. */ @@ -371,19 +406,21 @@ public function full_header() { } else if ($homepage == HOMEPAGE_SITE) { $homepagetype = 'site-index'; } - if ($this->page->include_region_main_settings_in_header_actions() && - !$this->page->blocks->is_block_present('settings')) { + if ( + $this->page->include_region_main_settings_in_header_actions() && + !$this->page->blocks->is_block_present('settings') + ) { // Only include the region main settings if the page has requested it and it doesn't already have // the settings block on it. The region main settings are included in the settings block and // duplicating the content causes behat failures. $this->page->add_header_action(html_writer::div( - $this->region_main_settings_menu(), - 'd-print-none', - ['id' => 'region-main-settings-menu'] + $this->region_main_settings_menu(), + 'd-print-none', + ['id' => 'region-main-settings-menu'] )); } - $header = new \stdClass(); + $header = new stdClass(); $header->settingsmenu = $this->context_header_settings_menu(); $header->contextheader = $this->context_header(); $header->hasnavbar = empty($this->page->layout_options['nonavbar']); @@ -441,13 +478,13 @@ public function navbar(): string { /** * Prints a nice side block with an optional header. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/core_renderer.php * * @param block_contents $bc HTML for the content * @param string $region the region the block is appearing in. * @return string the HTML to be output. */ - public function block(\block_contents $bc, $region) { + public function block(block_contents $bc, $region) { global $CFG; // Require own locallib.php. @@ -455,16 +492,16 @@ public function block(\block_contents $bc, $region) { $bc = clone($bc); // Avoid messing up the object passed in. if (empty($bc->blockinstanceid) || !strip_tags($bc->title)) { - $bc->collapsible = \block_contents::NOT_HIDEABLE; + $bc->collapsible = block_contents::NOT_HIDEABLE; } $id = !empty($bc->attributes['id']) ? $bc->attributes['id'] : uniqid('block-'); - $context = new \stdClass(); + $context = new stdClass(); $context->skipid = $bc->skipid; $context->blockinstanceid = $bc->blockinstanceid ?: uniqid('fakeid-'); $context->dockable = $bc->dockable; $context->id = $id; - $context->hidden = $bc->collapsible == \block_contents::HIDDEN; + $context->hidden = $bc->collapsible == block_contents::HIDDEN; $context->skiptitle = strip_tags($bc->title); $context->showskiplink = !empty($context->skiptitle); $context->arialabel = $bc->arialabel; @@ -494,7 +531,7 @@ public function block(\block_contents $bc, $region) { /** * Renders the login form. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/core_renderer.php * * @param \core_auth\output\login $form The renderable. * @return string @@ -510,8 +547,11 @@ public function render_login(\core_auth\output\login $form) { $url = $url->out(false); } $context->logourl = $url; - $context->sitename = format_string($SITE->fullname, true, - ['context' => context_course::instance(SITEID), "escape" => false]); + $context->sitename = format_string( + $SITE->fullname, + true, + ['context' => context_course::instance(SITEID), "escape" => false] + ); // Check if the local login form is enabled. $loginlocalloginsetting = get_config('theme_boost_union', 'loginlocalloginenable'); @@ -546,7 +586,7 @@ public function render_login(\core_auth\output\login $form) { * Content that should be output in the footer area * of the page. Designed to be called in theme layout.php files. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/core_renderer.php * * @return string HTML fragment. */ @@ -569,11 +609,6 @@ public function standard_footer_html() { return ''; } - // Ensure that the callback exists prior to cache purge. - // This is a critical page path. - // TODO MDL-81134 Remove after LTS+1. - require_once($CFG->libdir.'/classes/hook/output/before_standard_footer_html_generation.php'); - // Process the hooks as defined by Moodle core. // If Boost Union is configured to suppress a particular footer element, the hook has been disabled by // theme_boost_union_manipulate_books(). @@ -624,7 +659,7 @@ public function standard_footer_html() { * The standard tags (typically script tags that are not needed earlier) that * should be output after everything else. Designed to be called in theme layout.php files. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/core_renderer.php * * It is based on the standard_end_of_body_html() function but was split into two parts * (for the additionalhtmlfooter and the unique endtoken) to be requested individually in footer.mustache @@ -644,7 +679,7 @@ public function standard_end_of_body_html_endtoken() { * The standard tags (typically script tags that are not needed earlier) that * should be output after everything else. Designed to be called in theme layout.php files. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/core_renderer.php * * It is based on the standard_end_of_body_html() function but was split into two parts * (for the additionalhtmlfooter and the unique endtoken) to be requested individually in footer.mustache @@ -667,7 +702,7 @@ public function standard_end_of_body_html_additionalhtmlfooter() { $output = ''; if ($this->page->pagelayout !== 'embedded' && !empty($CFG->additionalhtmlfooter)) { - $output .= "\n".$CFG->additionalhtmlfooter; + $output .= "\n" . $CFG->additionalhtmlfooter; } return $output; } @@ -676,7 +711,7 @@ public function standard_end_of_body_html_additionalhtmlfooter() { * Returns a string containing a link to the user documentation. * Also contains an icon by default. Shown to teachers and admin only. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/core_renderer.php * * @param string $path The page link after doc root and language, no leading slash. * @param string $text The text to be displayed for the link @@ -701,8 +736,12 @@ public function doc_link($path, $text = '', $forcepopup = false, array $attribut $newwindowicon = ''; if (!empty($CFG->doctonewwindow) || $forcepopup) { $attributes['target'] = '_blank'; - $newwindowicon = $this->pix_icon('i/externallink', get_string('opensinnewwindow'), 'moodle', - ['class' => 'fa fa-externallink fa-fw']); + $newwindowicon = $this->pix_icon( + 'i/externallink', + get_string('opensinnewwindow'), + 'moodle', + ['class' => 'fa fa-externallink fa-fw'] + ); } return html_writer::tag('a', $icon . $text . $newwindowicon, $attributes); @@ -711,16 +750,18 @@ public function doc_link($path, $text = '', $forcepopup = false, array $attribut /** * Returns the services and support link for the help pop-up. * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/core_renderer.php * * @return string */ public function services_support_link(): string { global $CFG; - if (during_initial_install() || + if ( + during_initial_install() || (isset($CFG->showservicesandsupportcontent) && $CFG->showservicesandsupportcontent == false) || - !is_siteadmin()) { + !is_siteadmin() + ) { return ''; } @@ -734,7 +775,7 @@ public function services_support_link(): string { $liferingicon = null; } - $newwindowicon = $this->pix_icon('i/externallink', get_string('opensinnewwindow'), 'moodle', ['class' => 'ml-1']); + $newwindowicon = $this->pix_icon('i/externallink', get_string('opensinnewwindow'), 'moodle', ['class' => 'ms-1']); $link = !empty($CFG->servicespage) ? $CFG->servicespage : 'https://moodle.com/help/?utm_source=CTA-banner&utm_medium=platform&utm_campaign=name~Moodle4+cat~lms+mp~no'; @@ -746,7 +787,7 @@ public function services_support_link(): string { /** * Returns the HTML for the site support email link * - * This renderer function is copied and modified from /lib/outputrenderers.php + * This renderer function is copied and modified from /lib/classes/output/core_renderer.php * * @param array $customattribs Array of custom attributes for the support email anchor tag. * @param bool $embed Set to true if you want to embed the link in other inline content. @@ -757,9 +798,11 @@ public function supportemail(array $customattribs = [], bool $embed = false): st // Do not provide a link to contact site support if it is unavailable to this user. This would be where the site has // disabled support, or limited it to authenticated users and the current user is a guest or not logged in. - if (!isset($CFG->supportavailability) || + if ( + !isset($CFG->supportavailability) || $CFG->supportavailability == CONTACT_SUPPORT_DISABLED || - ($CFG->supportavailability == CONTACT_SUPPORT_AUTHENTICATED && (!isloggedin() || isguestuser()))) { + ($CFG->supportavailability == CONTACT_SUPPORT_AUTHENTICATED && (!isloggedin() || isguestuser())) + ) { return ''; } @@ -788,7 +831,7 @@ public function supportemail(array $customattribs = [], bool $embed = false): st if (!empty($CFG->supportpage)) { $attributes = ['href' => $CFG->supportpage, 'target' => 'blank']; - $content .= $this->pix_icon('i/externallink', '', 'moodle', ['class' => 'ml-1']); + $content .= $this->pix_icon('i/externallink', '', 'moodle', ['class' => 'ms-1']); } else { $attributes = ['href' => $CFG->wwwroot . '/user/contactsitesupport.php']; }