diff --git a/reportbuilder/classes/local/report/action.php b/reportbuilder/classes/local/report/action.php index 526325f9905..cd006305504 100644 --- a/reportbuilder/classes/local/report/action.php +++ b/reportbuilder/classes/local/report/action.php @@ -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); } /** diff --git a/reportbuilder/tests/local/report/action_test.php b/reportbuilder/tests/local/report/action_test.php index f1d0969e082..316a3f114e7 100644 --- a/reportbuilder/tests/local/report/action_test.php +++ b/reportbuilder/tests/local/report/action_test.php @@ -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('Yes', $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]); } }