From 80e2f8473e9b7aec8522aea76addcba1db4e3048 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..52a7448a440 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.9.8 === +* 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 be2f9ec66b1..a634ca92675 100644 --- a/lib/classes/dataformat.php +++ b/lib/classes/dataformat.php @@ -59,7 +59,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, @@ -89,7 +90,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; @@ -131,7 +132,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;