From 0dc10764b06e8e796bc925589d7e7886f5310242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Fri, 8 Nov 2024 14:03:39 +0100 Subject: [PATCH] MDL-81825 core: Replace sr_text() with visually_hidden_text() In core renderer, replace 'sr_text' method with 'visually_hidden_text' to be consistent with Bootstrap 5 upgrade. --- .upgradenotes/MDL-81825-2024110812525353.yml | 7 +++++++ backup/util/ui/backup_ui_setting.class.php | 2 +- .../output/local/content/cm/visibility.php | 2 +- .../output/local/content/section/visibility.php | 2 +- lib/classes/output/core_renderer.php | 16 +++++++++++++++- 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 .upgradenotes/MDL-81825-2024110812525353.yml diff --git a/.upgradenotes/MDL-81825-2024110812525353.yml b/.upgradenotes/MDL-81825-2024110812525353.yml new file mode 100644 index 0000000000000..c84092060a9f1 --- /dev/null +++ b/.upgradenotes/MDL-81825-2024110812525353.yml @@ -0,0 +1,7 @@ +issueNumber: MDL-81825 +notes: + core: + - message: >- + The 'core_renderer::sr_text()' function has been deprecated, use + 'core_renderer::visually_hidden_text()' instead. + type: deprecated diff --git a/backup/util/ui/backup_ui_setting.class.php b/backup/util/ui/backup_ui_setting.class.php index 9249c691fdebe..95bfb4f4d2e40 100644 --- a/backup/util/ui/backup_ui_setting.class.php +++ b/backup/util/ui/backup_ui_setting.class.php @@ -115,7 +115,7 @@ public function get_visually_hidden_label(): ?string { return null; } $renderer = $PAGE->get_renderer('core_backup'); - return $renderer->sr_text($this->altlabel); + return $renderer->visually_hidden_text($this->altlabel); } /** diff --git a/course/format/classes/output/local/content/cm/visibility.php b/course/format/classes/output/local/content/cm/visibility.php index 2af03a27bd43c..b791d608dbcc1 100644 --- a/course/format/classes/output/local/content/cm/visibility.php +++ b/course/format/classes/output/local/content/cm/visibility.php @@ -134,7 +134,7 @@ protected function get_dropdown_data( \renderer_base $output, choicelist $choice, ): stdClass { - $badgetext = $output->sr_text(get_string('availability')); + $badgetext = $output->visually_hidden_text(get_string('availability')); if (!$this->mod->visible) { $badgetext .= get_string('hiddenfromstudents'); diff --git a/course/format/classes/output/local/content/section/visibility.php b/course/format/classes/output/local/content/section/visibility.php index dbc38e45d6cd9..9c9d965597a2c 100644 --- a/course/format/classes/output/local/content/section/visibility.php +++ b/course/format/classes/output/local/content/section/visibility.php @@ -111,7 +111,7 @@ protected function is_section_visibility_editable(): bool { * @return array */ protected function get_visibility_dropdown(\renderer_base $output): array { - $badgetext = $output->sr_text(get_string('availability')); + $badgetext = $output->visually_hidden_text(get_string('availability')); $badgetext .= get_string('hiddenfromstudents'); $icon = $this->get_icon('hide'); diff --git a/lib/classes/output/core_renderer.php b/lib/classes/output/core_renderer.php index 33d278f3743da..9fd50020fab96 100644 --- a/lib/classes/output/core_renderer.php +++ b/lib/classes/output/core_renderer.php @@ -2952,12 +2952,26 @@ public function paragraph(string $contents, ?string $classes = null, ?string $id * * @param string $contents The contents of the paragraph * @return string the HTML to output. + * @deprecated since 5.0. Use visually_hidden_text() instead. + * @todo Final deprecation in Moodle 6.0. See MDL-83671. */ + #[\core\attribute\deprecated('core_renderer::visually_hidden_text()', since: '5.0', mdl: 'MDL-81825')] public function sr_text(string $contents): string { + \core\deprecation::emit_deprecation_if_present([$this, __FUNCTION__]); + return $this->visually_hidden_text($contents); + } + + /** + * Outputs a visually hidden inline text (but accessible to assistive technologies). + * + * @param string $contents The contents of the paragraph + * @return string the HTML to output. + */ + public function visually_hidden_text(string $contents): string { return html_writer::tag( 'span', $contents, - ['class' => 'sr-only'] + ['class' => 'visually-hidden'] ) . ' '; }