From b73a685ef72d4e5fc2f3ed18219fb8a647cd9ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Fri, 1 Mar 2024 12:29:08 +0100 Subject: [PATCH] MDL-81050 output: Add new 'attributes' parameter to container --- lib/outputrenderers.php | 12 +++++++----- lib/upgrade.txt | 2 ++ mod/wiki/pagelib.php | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 5852068f61b..93519e37dda 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -3404,10 +3404,11 @@ EOD; * @param string $contents The contents of the box * @param string $classes A space-separated list of CSS classes * @param string $id An optional ID + * @param array $attributes Optional other attributes as array * @return string the HTML to output. */ - public function container($contents, $classes = null, $id = null) { - return $this->container_start($classes, $id) . $contents . $this->container_end(); + public function container($contents, $classes = null, $id = null, $attributes = []) { + return $this->container_start($classes, $id, $attributes) . $contents . $this->container_end(); } /** @@ -3415,12 +3416,13 @@ EOD; * * @param string $classes A space-separated list of CSS classes * @param string $id An optional ID + * @param array $attributes Optional other attributes as array * @return string the HTML to output. */ - public function container_start($classes = null, $id = null) { + public function container_start($classes = null, $id = null, $attributes = []) { $this->opencontainers->push('container', html_writer::end_tag('div')); - return html_writer::start_tag('div', array('id' => $id, - 'class' => renderer_base::prepare_classes($classes))); + $attributes = array_merge(['id' => $id, 'class' => renderer_base::prepare_classes($classes)], $attributes); + return html_writer::start_tag('div', $attributes); } /** diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 1c94bf2a7db..3d02d603ede 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -90,6 +90,8 @@ information provided here is intended especially for developers. - `question_category_options` - `question_add_context_in_key` - `question_fix_top_names` +* Added a new parameter to `core_renderer::container` and `core_renderer::container_start` to allow for the addition of + custom attributes. === 4.3 === diff --git a/mod/wiki/pagelib.php b/mod/wiki/pagelib.php index d87eb6e17dd..11c1887d57a 100644 --- a/mod/wiki/pagelib.php +++ b/mod/wiki/pagelib.php @@ -2216,7 +2216,7 @@ class page_wiki_viewversion extends page_wiki { $pageversion->content = file_rewrite_pluginfile_urls($pageversion->content, 'pluginfile.php', $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id); $parseroutput = wiki_parse_content($pageversion->contentformat, $pageversion->content, $options); - $content = $OUTPUT->container(format_text($parseroutput['parsed_text'], FORMAT_HTML, array('overflowdiv'=>true)), false, '', '', true); + $content = $OUTPUT->container(format_text($parseroutput['parsed_text'], FORMAT_HTML, ['overflowdiv' => true])); echo $OUTPUT->box($content, 'generalbox wiki_contentbox'); } else {