mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 20:53:53 +01:00
MDL-74173 reportbuilder: Convert action links to action menu links
This commit is contained in:
parent
01eb6d2e9b
commit
6e528ca463
@ -18,6 +18,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\report;
|
||||
|
||||
use action_menu_link;
|
||||
use lang_string;
|
||||
use moodle_url;
|
||||
use pix_icon;
|
||||
@ -94,14 +95,13 @@ final class action {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return rendered action link suitable for output, or null if the action cannot be displayed (because one of it's callbacks
|
||||
* Return action menu link suitable for output, or null if the action cannot be displayed (because one of its callbacks
|
||||
* returned false, {@see add_callback})
|
||||
*
|
||||
* @param stdClass $row
|
||||
* @return string|null
|
||||
* @return action_menu_link|null
|
||||
*/
|
||||
public function get_action_link(stdClass $row): ?string {
|
||||
global $OUTPUT;
|
||||
public function get_action_link(stdClass $row): ?action_menu_link {
|
||||
|
||||
foreach ($this->callbacks as $callback) {
|
||||
$row = clone $row; // Clone so we don't modify the shared row inside a callback.
|
||||
@ -116,8 +116,6 @@ final class action {
|
||||
self::replace_placeholders($this->url->params(), $row)
|
||||
);
|
||||
|
||||
$this->attributes['role'] = 'button';
|
||||
|
||||
// Ensure we have a title attribute set, if one wasn't already provided.
|
||||
if (!array_key_exists('title', $this->attributes)) {
|
||||
$this->attributes['title'] = (string) $this->title;
|
||||
@ -136,7 +134,7 @@ final class action {
|
||||
$title = $attributes['title'];
|
||||
unset($attributes['title']);
|
||||
|
||||
return $OUTPUT->action_link($url, $title, null, $attributes, $this->icon);
|
||||
return new action_menu_link($url, $this->icon, $title, null, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +100,7 @@ class action_test extends advanced_testcase {
|
||||
|
||||
// Assert correct title appears inside action link, after the icon.
|
||||
$actionlink = $action->get_action_link((object) $row);
|
||||
$this->assertStringEndsWith('</i>Yes</a>', $actionlink);
|
||||
$this->assertEquals('Yes', $actionlink->text);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,7 +112,7 @@ class action_test extends advanced_testcase {
|
||||
|
||||
// This is the action URL we expect.
|
||||
$expectedactionurl = (new moodle_url('/', ['id' => 42, 'action' => 'edit']))->out(false);
|
||||
$this->assertStringContainsString("href=\"{$expectedactionurl}\"", $actionlink);
|
||||
$this->assertEquals($expectedactionurl, $actionlink->url->out(false));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,7 +128,7 @@ class action_test extends advanced_testcase {
|
||||
'data-action' => 'edit',
|
||||
];
|
||||
foreach ($expectedattributes as $key => $value) {
|
||||
$this->assertStringContainsString("{$key}=\"{$value}\"", $actionlink);
|
||||
$this->assertEquals($value, $actionlink->attributes[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user