MDL-52046 reportbuilder: Support null return from checkbox callback

This commit is contained in:
David Woloszyn 2024-06-18 15:17:11 +10:00
parent 2bf886f9dd
commit 1b1128d646
2 changed files with 14 additions and 2 deletions

View File

@ -0,0 +1,8 @@
issueNumber: MDL-52046
notes:
core_reportbuilder:
- message: >-
The return type of the `set_checkbox_toggleall` callback, defined by
system reports, can now be null. Use if the checkbox should not be shown
for the row.
type: improved

View File

@ -143,7 +143,7 @@ abstract class system_report extends base {
* Define toggle all checkbox for the report, required row data should be defined by calling {@see add_base_fields}
*
* @param callable $callback Callback to return value/label for each checkbox, implementing the following signature:
* function(stdClass $row): array containing value/label pair
* function(stdClass $row): ?array containing value/label pair, or null if the checkbox should not be shown for the row
*/
final protected function set_checkbox_toggleall(callable $callback): void {
$this->checkboxcallback = $callback;
@ -166,7 +166,11 @@ abstract class system_report extends base {
$value = '';
$label = get_string('selectall');
} else {
[$value, $label] = ($this->checkboxcallback)($row);
$checkboxdata = ($this->checkboxcallback)($row);
if ($checkboxdata === null) {
return null;
}
[$value, $label] = $checkboxdata;
}
return new checkbox_toggleall('report-select-all', $ismaster, [