From a586e952fff4e4e2c1e6d8d28ae633b263f74b9d Mon Sep 17 00:00:00 2001 From: Ferran Recio Date: Wed, 26 Jul 2023 15:37:47 +0200 Subject: [PATCH] MDL-78282 output: new sr_text renderer method Some output classes require pre-rendered elements. In some cases, those elements require some screen reader extra texts (especially in buttons). The st_text method allow the outputs to create those inline tags without using html_writer. Furthermore, the current screen reader classes are based on bootstrap, having them isolated in renderer methods allow themes to implement alternatives accessibility HTML structures. --- lib/outputrenderers.php | 14 ++++++++++++++ lib/upgrade.txt | 1 + 2 files changed, 15 insertions(+) diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 5d177fed286..b1cbf57c290 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -3277,6 +3277,20 @@ EOD; ); } + /** + * Outputs a screen reader only inline text. + * + * @param string $contents The contents of the paragraph + * @return string the HTML to output. + */ + public function sr_text(string $contents): string { + return html_writer::tag( + 'span', + $contents, + ['class' => 'sr-only'] + ) . ' '; + } + /** * Outputs a container. * diff --git a/lib/upgrade.txt b/lib/upgrade.txt index b07dcec3ab3..7df51950287 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -53,6 +53,7 @@ information provided here is intended especially for developers. the page displays a heading for the activity (usually a h2 heading containing the activity name). * New method moodleform::filter_shown_headers() is created to show some expanded headers only and hide the rest. * count_words() and count_letters() have a new optional parameter called $format to format the text before doing the counting. +* New core_renderer::sr_text method to generate screen reader only inline texts without using html_writter. === 4.2 ===