diff --git a/course/classes/output/category_action_bar.php b/course/classes/output/category_action_bar.php index 45cb61dd8e0..68c5e51407c 100644 --- a/course/classes/output/category_action_bar.php +++ b/course/classes/output/category_action_bar.php @@ -16,6 +16,8 @@ namespace core_course\output; +use action_menu; +use action_menu_link_secondary; use context_coursecat; use core_course_category; use course_request; @@ -161,10 +163,26 @@ class category_action_bar extends manage_categories_action_bar { * - additionaloptions Additional actions that can be performed in a category */ public function export_for_template(\renderer_base $output): array { + $additionaloptions = $this->get_additional_category_options(); + // Generate the action menu if there are additional options. + if (!empty($additionaloptions)) { + $actionmenu = new action_menu(); + $actionmenu->set_kebab_trigger(get_string('moreactions')); + $actionmenu->set_additional_classes('ms-auto'); + foreach ($additionaloptions['options'] as $option) { + $actionmenu->add(new action_menu_link_secondary( + $option['url'], + null, + $option['string'] + )); + } + $actionmenucontent = $output->render($actionmenu); + } + return [ 'categoryselect' => $this->get_category_select($output), 'search' => $this->get_search_form(), - 'additionaloptions' => $this->get_additional_category_options() + 'additionaloptions' => $actionmenucontent ?? '', ]; } diff --git a/course/templates/category_actionbar.mustache b/course/templates/category_actionbar.mustache index ec482c4ef33..5e2766d8f9b 100644 --- a/course/templates/category_actionbar.mustache +++ b/course/templates/category_actionbar.mustache @@ -98,20 +98,6 @@ {{> core/search_input }} {{/search}} - {{#additionaloptions}} -
- -
- {{/additionaloptions}} + {{{additionaloptions}}} diff --git a/course/tests/behat/course_request.feature b/course/tests/behat/course_request.feature index beb5988578b..480b0db706e 100644 --- a/course/tests/behat/course_request.feature +++ b/course/tests/behat/course_request.feature @@ -22,7 +22,7 @@ Feature: Users can request and approve courses | moodle/course:request | allow | When I log in as "user1" And I am on course index - And I click on "More actions" "button" + And I click on "More actions" "link" And I click on "Request a course" "link" And I set the following fields to these values: | Course full name | My new course | @@ -36,7 +36,7 @@ Feature: Users can request and approve courses And I log out And I log in as "user2" And I am on course index - And I click on "More actions" "button" + And I click on "More actions" "link" And I click on "Courses pending approval" "link" And the following should exist in the "pendingcourserequests" table: | Requested by | Course short name | Course full name | Category | Reason for course request | @@ -75,7 +75,7 @@ Feature: Users can request and approve courses And I log in as "user1" And I am on course index And I follow "English category" - And I click on "More actions" "button" + And I click on "More actions" "link" And I click on "Request a course" "link" And I should see "English category" in the ".form-autocomplete-selection" "css_element" And I set the following fields to these values: @@ -91,7 +91,7 @@ Feature: Users can request and approve courses And I should not see "Courses pending approval" And I am on course index And I follow "Science category" - And I click on "More actions" "button" + And I click on "More actions" "link" And I click on "Courses pending approval" "link" And I should not see "Mynewcourse" And I press "Back to course listing" @@ -99,7 +99,7 @@ Feature: Users can request and approve courses And I log in as "user3" And I am on course index And I follow "English category" - And I click on "More actions" "button" + And I click on "More actions" "link" And I click on "Courses pending approval" "link" And the following should exist in the "pendingcourserequests" table: | Requested by | Course short name | Course full name | Category | Reason for course request |