diff --git a/badges/classes/output/base_action_bar.php b/badges/classes/output/base_action_bar.php index 6b89d331338..2cc11b6a686 100644 --- a/badges/classes/output/base_action_bar.php +++ b/badges/classes/output/base_action_bar.php @@ -17,8 +17,10 @@ namespace core_badges\output; use renderable; -use templatable; +use renderer_base; use moodle_page; +use navigation_node; +use templatable; /** * Abstract class for the badges tertiary navigation. The class initialises the page and type class variables. @@ -50,4 +52,52 @@ abstract class base_action_bar implements renderable, templatable { * @return string */ abstract public function get_template(): string; + + /** + * Gets additional third party navigation nodes for display. + * + * @param renderer_base $output The output + * @return array All that sweet third party navigation action. + */ + public function get_third_party_nav_action(renderer_base $output): array { + $badgenode = $this->page->settingsnav->find('coursebadges', navigation_node::TYPE_CONTAINER); + if (!$badgenode) { + return []; + } + $leftovernodes = []; + foreach ($badgenode->children as $key => $value) { + if (array_search($value->key, $this->expected_items()) === false) { + $leftovernodes[] = $value; + } + } + $result = \core\navigation\views\secondary::create_menu_element($leftovernodes); + + if ($result == false) { + return []; + } else { + $data ['thirdpartybutton'] = true; + if (count($result) == 1) { + // Return a button. + $link = key($result); + $text = current($result); + $data['thirdpartynodes'] = ['link' => $link, 'text' => $text]; + } else { + // Return a url_select. + $selectobject = new \url_select($result, $this->page->url, get_string('othernavigation', 'badges')); + $data['thirdpartynodes'] = $selectobject->export_for_template($output); + $data['thirdpartybutton'] = false; + } + } + + return $data; + } + + /** + * Expected navigation node keys for badges. + * + * @return array default badge navigation node keys. + */ + protected function expected_items(): array { + return ['coursebadges', 'newbadge']; + } } diff --git a/badges/classes/output/manage_badge_action_bar.php b/badges/classes/output/manage_badge_action_bar.php index 5cc712b5237..7344b72d47d 100644 --- a/badges/classes/output/manage_badge_action_bar.php +++ b/badges/classes/output/manage_badge_action_bar.php @@ -71,6 +71,8 @@ class manage_badge_action_bar extends base_action_bar { foreach ($elements as $key => $element) { $elements[$key] = $element->export_for_template($output); } + $additional = $this->get_third_party_nav_action($output); + $elements += $additional ?: []; return $elements; } diff --git a/badges/classes/output/recipients_action_bar.php b/badges/classes/output/recipients_action_bar.php index 6720aff31cd..cae5ba7ce91 100644 --- a/badges/classes/output/recipients_action_bar.php +++ b/badges/classes/output/recipients_action_bar.php @@ -53,6 +53,8 @@ class recipients_action_bar extends manage_badge_action_bar { $button = new single_button($url, get_string('award', 'badges'), 'post', true); $elements['awardbutton'] = $button->export_for_template($output); } + $thirdpartynav = $this->get_third_party_nav_action($output); + $elements += $thirdpartynav ?: []; return $elements; } diff --git a/badges/classes/output/standard_action_bar.php b/badges/classes/output/standard_action_bar.php index 951d91e24cf..93026a087b2 100644 --- a/badges/classes/output/standard_action_bar.php +++ b/badges/classes/output/standard_action_bar.php @@ -96,6 +96,10 @@ class standard_action_bar extends base_action_bar { $buttons[$key] = $button->export_for_template($output); } - return ['buttons' => $buttons]; + $data = ['buttons' => $buttons]; + $additional = $this->get_third_party_nav_action($output); + $data += $additional ?: []; + + return $data; } } diff --git a/badges/templates/award_badge.mustache b/badges/templates/award_badge.mustache index 7e2ab5e50cb..bdae5a7c451 100644 --- a/badges/templates/award_badge.mustache +++ b/badges/templates/award_badge.mustache @@ -103,5 +103,6 @@ {{> core/single_button }} {{/awardbutton}} + {{> core_badges/badge_more_nav }} diff --git a/badges/templates/badge_more_nav.mustache b/badges/templates/badge_more_nav.mustache new file mode 100644 index 00000000000..622d5a57e31 --- /dev/null +++ b/badges/templates/badge_more_nav.mustache @@ -0,0 +1,37 @@ +{{! + This file is part of Moodle - http://moodle.org/ + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template core_badges/badge_more_nav + + Example context (json): + { + "thirdpartybutton": true, + "thirdpartynodes": { + "link": "http://example.org/help", + "text": "Example text" + } + } +}} +{{#thirdpartybutton}} + {{#thirdpartynodes}} +
+ {{text}} +
+ {{/thirdpartynodes}} +{{/thirdpartybutton}} +{{^thirdpartybutton}} + {{#thirdpartynodes}} + {{> core/url_select}} + {{/thirdpartynodes}} +{{/thirdpartybutton}} diff --git a/badges/templates/manage_badge.mustache b/badges/templates/manage_badge.mustache index 04803875cc1..081c3eeb45b 100644 --- a/badges/templates/manage_badge.mustache +++ b/badges/templates/manage_badge.mustache @@ -83,5 +83,6 @@ {{> core/url_select }} {{/urlselect}} + {{> core_badges/badge_more_nav }} diff --git a/badges/templates/manage_badges.mustache b/badges/templates/manage_badges.mustache index 4fe4c3c56e3..7c4c4b8143d 100644 --- a/badges/templates/manage_badges.mustache +++ b/badges/templates/manage_badges.mustache @@ -59,5 +59,6 @@ {{> core/single_button }} {{/buttons}} + {{> core_badges/badge_more_nav }} diff --git a/lang/en/badges.php b/lang/en/badges.php index 499d1ed47b6..35313af6957 100644 --- a/lang/en/badges.php +++ b/lang/en/badges.php @@ -456,6 +456,7 @@ $string['oauth2issuer'] = 'OAuth 2 services'; $string['openbadgesv1'] = 'Open Badges v1.0'; $string['openbadgesv2'] = 'Open Badges v2.0'; $string['openbadgesv2p1'] = 'Open Badges v2.1'; +$string['othernavigation'] = 'Other navigation ...'; $string['potentialrecipients'] = 'Potential badge recipients'; $string['preferences'] = 'Badge preferences'; $string['privacy:metadata:backpack'] = 'A record of user\'s backpacks';