From 0eaaf40f102d703cc22e5f749625ffd28a3d2e9b Mon Sep 17 00:00:00 2001 From: Ferran Recio Date: Thu, 18 May 2023 12:22:23 +0200 Subject: [PATCH] MDL-78175 output: new paragraph renderer method Many main php files still uses html_writer('p...) to render a simple paragraphs below or under other elements like forms. In many cases those texts could be part of a template but there are may scenarios were creating a full template for a simple paragraph is too much. However, the html_writer is too limiting as plugins cannot provide their own implementation. This new method in the renderer is a good in between solution. --- enrol/renameroles.php | 2 +- lib/outputrenderers.php | 16 ++++++++++++++++ lib/upgrade.txt | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/enrol/renameroles.php b/enrol/renameroles.php index 6ba3436a8ba..7181d368175 100644 --- a/enrol/renameroles.php +++ b/enrol/renameroles.php @@ -50,7 +50,7 @@ echo $OUTPUT->header(); echo $OUTPUT->render_participants_tertiary_nav($course); echo $OUTPUT->heading(get_string('rolerenaming')); -echo $OUTPUT->container(get_string('rolerenaming_help')); +echo $OUTPUT->paragraph(get_string('rolerenaming_help')); $customdata = [ 'id' => $course->id, diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index bc798b5d91a..d327479c48e 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -3263,6 +3263,22 @@ EOD; return $this->opencontainers->pop('box'); } + /** + * Outputs a paragraph. + * + * @param string $contents The contents of the paragraph + * @param string|null $classes A space-separated list of CSS classes + * @param string|null $id An optional ID + * @return string the HTML to output. + */ + public function paragraph(string $contents, ?string $classes = null, ?string $id = null): string { + return html_writer::tag( + 'p', + $contents, + ['id' => $id, 'class' => renderer_base::prepare_classes($classes)] + ); + } + /** * Outputs a container. * diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 7f6c47eec36..ad1a7299b2a 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -7,6 +7,7 @@ information provided here is intended especially for developers. - admin_setting_requiredpasswordunmask * The badges_get_oauth2_service_options() method has been deprecated, because it's not required anymore. It should no longer be used. +* New core_renderer::paragraph method to replace the overused html_writer::tag('p', ...) pattern. === 4.2 ===