From f3b3684e5b5f2539e17b0e6b788cefc985f797cf Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Fri, 18 Jun 2021 10:15:27 +0100 Subject: [PATCH] MDL-71981 dataformat: indicate HTML support in writer callback. --- dataformat/upgrade.txt | 7 +++++++ lib/classes/dataformat.php | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/dataformat/upgrade.txt b/dataformat/upgrade.txt index 89eaa5bce0c..687ea7392c5 100644 --- a/dataformat/upgrade.txt +++ b/dataformat/upgrade.txt @@ -1,6 +1,13 @@ This files describes API changes in /dataformat/ download system, information provided here is intended especially for developers. +=== 3.11.1 === +* Optional $callback for the following \core\dataformat methods now receive a second argument to define + whether the current format writer supports HTML: + - download_data() + - write_data() + - write_data_to_filearea() + === 3.9 === * The following methods have been added to the base dataformat class to allow instances to export to a local file. They can be overridden in extending classes to define how files should be created: diff --git a/lib/classes/dataformat.php b/lib/classes/dataformat.php index 0bc54536385..70bdcec5a6b 100644 --- a/lib/classes/dataformat.php +++ b/lib/classes/dataformat.php @@ -60,7 +60,8 @@ class dataformat { * @param string $dataformat * @param array $columns * @param Iterable $iterator - * @param callable|null $callback + * @param callable|null $callback Optional callback method to apply to each record prior to writing, which accepts two + * parameters as such: function($record, bool $supportshtml) returning formatted record * @throws coding_exception */ public static function download_data(string $filename, string $dataformat, array $columns, Iterable $iterator, @@ -90,7 +91,7 @@ class dataformat { $rownum = 0; foreach ($iterator as $row) { if (is_callable($callback)) { - $row = $callback($row); + $row = $callback($row, $format->supports_html()); } if ($row === null) { continue; @@ -132,7 +133,7 @@ class dataformat { $rownum = 0; foreach ($iterator as $row) { if (is_callable($callback)) { - $row = $callback($row); + $row = $callback($row, $format->supports_html()); } if ($row === null) { continue; -- 2.43.0