From 23c8c0657efcc5dc4aa6e2a6305acf2725db6db4 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 16 Apr 2025 19:51:52 +0100 Subject: [PATCH] MDL-85216 reportbuilder: allow pixicon to be passed to report actions. --- .upgradenotes/MDL-85216-2025041619113672.yml | 7 +++++++ .../classes/external/report_action_exporter.php | 17 +++++++++++++++-- reportbuilder/classes/output/report_action.php | 5 ++++- reportbuilder/templates/report.mustache | 10 +++++++++- .../external/report_action_exporter_test.php | 9 ++++++++- .../tests/external/reports/get_test.php | 9 ++++++++- 6 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 .upgradenotes/MDL-85216-2025041619113672.yml diff --git a/.upgradenotes/MDL-85216-2025041619113672.yml b/.upgradenotes/MDL-85216-2025041619113672.yml new file mode 100644 index 00000000000..c9995c70a47 --- /dev/null +++ b/.upgradenotes/MDL-85216-2025041619113672.yml @@ -0,0 +1,7 @@ +issueNumber: MDL-85216 +notes: + core_reportbuilder: + - message: >- + The `report_action` class now accepts a `pix_icon` to include inside the + rendered action element + type: improved diff --git a/reportbuilder/classes/external/report_action_exporter.php b/reportbuilder/classes/external/report_action_exporter.php index a63d635c4e2..973e10834ff 100644 --- a/reportbuilder/classes/external/report_action_exporter.php +++ b/reportbuilder/classes/external/report_action_exporter.php @@ -54,7 +54,15 @@ class report_action_exporter extends exporter { 'type' => PARAM_ALPHA, ], 'title' => [ - 'type' => PARAM_TEXT, + 'type' => PARAM_RAW, + ], + 'icon' => [ + 'type' => [ + 'key' => ['type' => PARAM_RAW], + 'component' => ['type' => PARAM_COMPONENT], + 'title' => ['type' => PARAM_NOTAGS], + ], + 'optional' => true, ], 'attributes' => [ 'type' => [ @@ -98,10 +106,15 @@ class report_action_exporter extends exporter { return ['name' => $key, 'value' => $value]; }, array_keys($reportaction->attributes), $reportaction->attributes); + $optionalvalues = []; + if ($reportaction->icon !== null) { + $optionalvalues['icon'] = $reportaction->icon->export_for_pix(); + } + return [ 'tag' => $reportaction->tag ?: 'button', 'title' => $reportaction->title, 'attributes' => $attributes, - ]; + ] + $optionalvalues; } } diff --git a/reportbuilder/classes/output/report_action.php b/reportbuilder/classes/output/report_action.php index 652cb746c32..07448d18a1a 100644 --- a/reportbuilder/classes/output/report_action.php +++ b/reportbuilder/classes/output/report_action.php @@ -18,7 +18,7 @@ declare(strict_types=1); namespace core_reportbuilder\output; -use core\output\{renderer_base, templatable}; +use core\output\{pix_icon, renderer_base, templatable}; use core_reportbuilder\external\report_action_exporter; /** @@ -36,6 +36,7 @@ class report_action implements templatable { * @param string $title * @param array $attributes * @param string $tag + * @param pix_icon|null $icon */ public function __construct( /** @var string */ @@ -44,6 +45,8 @@ class report_action implements templatable { public readonly array $attributes, /** @var string */ public readonly string $tag = 'button', + /** @var pix_icon|null */ + public readonly ?pix_icon $icon = null, ) { } diff --git a/reportbuilder/templates/report.mustache b/reportbuilder/templates/report.mustache index c15911bf120..511d5c738e7 100644 --- a/reportbuilder/templates/report.mustache +++ b/reportbuilder/templates/report.mustache @@ -33,6 +33,11 @@ "button": { "tag": "button", "title": "Click me", + "icon": { + "key": "t/add", + "component": "moodle", + "title": "Click me" + }, "attributes": [{ "name": "class", "value": "btn btn-primary" @@ -54,7 +59,10 @@ {{! Action buttons }}