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.
This commit is contained in:
Ferran Recio 2023-05-18 12:22:23 +02:00
parent 0ad8fd077c
commit 0eaaf40f10
3 changed files with 18 additions and 1 deletions

View file

@ -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,

View file

@ -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.
*

View file

@ -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 ===