MDL-85216 reportbuilder: allow pixicon to be passed to report actions.
This commit is contained in:
@@ -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
|
||||
+15
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
@@ -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 }}
|
||||
<div class="dropdown d-flex justify-content-end mb-3">
|
||||
{{#button}}
|
||||
<{{{tag}}} {{#attributes}}{{name}}="{{value}}" {{/attributes}}>{{title}}</{{{tag}}}>
|
||||
<{{{tag}}} {{#attributes}}{{name}}="{{value}}" {{/attributes}}>
|
||||
{{#icon}}{{#pix}}{{key}}, {{component}}, {{{title}}}{{/pix}}{{/icon}}
|
||||
{{{title}}}
|
||||
</{{{tag}}}>
|
||||
{{/button}}
|
||||
{{#filterspresent}}
|
||||
{{>core_reportbuilder/local/filters/area}}
|
||||
|
||||
@@ -19,6 +19,7 @@ declare(strict_types=1);
|
||||
namespace core_reportbuilder\external;
|
||||
|
||||
use advanced_testcase;
|
||||
use core\output\pix_icon;
|
||||
use core_reportbuilder\output\report_action;
|
||||
|
||||
/**
|
||||
@@ -37,7 +38,8 @@ final class report_action_exporter_test extends advanced_testcase {
|
||||
public function test_export(): void {
|
||||
global $PAGE;
|
||||
|
||||
$reportaction = new report_action('Add', ['class' => 'btn', 'data-action' => 'action']);
|
||||
$reportaction = new report_action('Add', ['class' => 'btn', 'data-action' => 'action'], 'button',
|
||||
new pix_icon('t/add', 'Add'));
|
||||
|
||||
$exporter = new report_action_exporter(null, ['reportaction' => $reportaction]);
|
||||
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
|
||||
@@ -45,6 +47,11 @@ final class report_action_exporter_test extends advanced_testcase {
|
||||
$this->assertEquals((object) [
|
||||
'tag' => 'button',
|
||||
'title' => 'Add',
|
||||
'icon' => [
|
||||
'key' => 't/add',
|
||||
'component' => 'moodle',
|
||||
'title' => 'Add',
|
||||
],
|
||||
'attributes' => [
|
||||
['name' => 'class', 'value' => 'btn'],
|
||||
['name' => 'data-action', 'value' => 'action'],
|
||||
|
||||
+8
-1
@@ -19,6 +19,7 @@ declare(strict_types=1);
|
||||
namespace core_reportbuilder\external\reports;
|
||||
|
||||
use context_system;
|
||||
use core\output\pix_icon;
|
||||
use core_reportbuilder_generator;
|
||||
use core_external\external_api;
|
||||
use externallib_advanced_testcase;
|
||||
@@ -100,7 +101,8 @@ final class get_test extends externallib_advanced_testcase {
|
||||
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
|
||||
|
||||
$instance = manager::get_report_from_persistent($report);
|
||||
$instance->set_report_action(new report_action('Add', ['class' => 'btn', 'data-action' => 'action']));
|
||||
$instance->set_report_action(new report_action('Add', ['class' => 'btn', 'data-action' => 'action'], 'button',
|
||||
new pix_icon('t/add', 'Add')));
|
||||
$instance->set_report_info_container('Hello');
|
||||
|
||||
// Add two filters.
|
||||
@@ -118,6 +120,11 @@ final class get_test extends externallib_advanced_testcase {
|
||||
$this->assertEquals([
|
||||
'tag' => 'button',
|
||||
'title' => 'Add',
|
||||
'icon' => [
|
||||
'key' => 't/add',
|
||||
'component' => 'moodle',
|
||||
'title' => 'Add',
|
||||
],
|
||||
'attributes' => [
|
||||
['name' => 'class', 'value' => 'btn'],
|
||||
['name' => 'data-action', 'value' => 'action'],
|
||||
|
||||
Reference in New Issue
Block a user