From 8657c6fde83dfe8c0ac55df1efd7792698ec360c Mon Sep 17 00:00:00 2001 From: jfederico Date: Thu, 4 Sep 2025 20:58:02 +0000 Subject: [PATCH] MDL-84903 mdl_bigbluebuttonbn: overrides view through bbbext plugins --- .../mod/bigbluebuttonbn/classes/extension.php | 20 +++++++ .../local/extension/view_page_addons.php | 28 ++++++++++ .../classes/output/renderer.php | 13 ----- .../classes/output/view_page.php | 13 ++++- .../tests/behat/subplugins.feature | 12 +++- .../bigbluebuttonbn/view_page_addons.php | 56 +++++++++++++++++++ .../templates/view_page_addons.mustache | 46 +++++++++++++++ public/mod/bigbluebuttonbn/view.php | 7 ++- 8 files changed, 177 insertions(+), 18 deletions(-) create mode 100644 public/mod/bigbluebuttonbn/classes/local/extension/view_page_addons.php create mode 100644 public/mod/bigbluebuttonbn/tests/fixtures/extension/complex/classes/bigbluebuttonbn/view_page_addons.php create mode 100644 public/mod/bigbluebuttonbn/tests/fixtures/extension/complex/templates/view_page_addons.mustache diff --git a/public/mod/bigbluebuttonbn/classes/extension.php b/public/mod/bigbluebuttonbn/classes/extension.php index 9ba37cf0fda..14b03ac0a67 100644 --- a/public/mod/bigbluebuttonbn/classes/extension.php +++ b/public/mod/bigbluebuttonbn/classes/extension.php @@ -24,6 +24,7 @@ use mod_bigbluebuttonbn\local\extension\mod_form_addons; use mod_bigbluebuttonbn\local\extension\mod_instance_helper; use mod_bigbluebuttonbn\local\extension\navigation_append_addon; use mod_bigbluebuttonbn\local\extension\navigation_override_addon; +use mod_bigbluebuttonbn\local\extension\view_page_addons; use stdClass; use core_plugin_manager; use core_component; @@ -291,4 +292,23 @@ class extension { } return false; } + + /** + * Get rendered output for override in the instance. + * + * @param \renderer_base $renderer + * @param instance $instance + * @return string|null Rendered information for the instance, or null if no override found. + */ + public static function get_rendered_output_override($renderer, $instance): ?string { + $classes = self::get_classes_implementing(view_page_addons::class); + if (!empty($classes)) { + $outputclass = reset($classes); + if (class_exists($outputclass)) { + return $renderer->render(new $outputclass($instance)); + } + } + // Fallback to the default rendered output if no subplugin overrides it. + return null; + } } diff --git a/public/mod/bigbluebuttonbn/classes/local/extension/view_page_addons.php b/public/mod/bigbluebuttonbn/classes/local/extension/view_page_addons.php new file mode 100644 index 00000000000..f47c73c9976 --- /dev/null +++ b/public/mod/bigbluebuttonbn/classes/local/extension/view_page_addons.php @@ -0,0 +1,28 @@ +. + +namespace mod_bigbluebuttonbn\local\extension; + +/** + * A single action class to mutate the action URL. + * + * @package mod_bigbluebuttonbn + * @copyright 2025 onwards, Blindside Networks Inc + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) + */ +abstract class view_page_addons extends \mod_bigbluebuttonbn\output\view_page { +} diff --git a/public/mod/bigbluebuttonbn/classes/output/renderer.php b/public/mod/bigbluebuttonbn/classes/output/renderer.php index fde004cd65c..50de1b6aded 100644 --- a/public/mod/bigbluebuttonbn/classes/output/renderer.php +++ b/public/mod/bigbluebuttonbn/classes/output/renderer.php @@ -85,19 +85,6 @@ class renderer extends plugin_renderer_base { return $groupsmenu . '

'; } - /** - * Render the view page. - * - * @param view_page $page - * @return string - */ - public function render_view_page(view_page $page): string { - return $this->render_from_template( - 'mod_bigbluebuttonbn/view_page', - $page->export_for_template($this) - ); - } - /** * Render inplace editable * diff --git a/public/mod/bigbluebuttonbn/classes/output/view_page.php b/public/mod/bigbluebuttonbn/classes/output/view_page.php index 40654ea66e3..355f33717bc 100644 --- a/public/mod/bigbluebuttonbn/classes/output/view_page.php +++ b/public/mod/bigbluebuttonbn/classes/output/view_page.php @@ -55,12 +55,20 @@ class view_page implements renderable, templatable { * @param renderer_base $output * @return stdClass */ - public function export_for_template(renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): \stdClass { + // By default use group selector from the plugin renderer. + global $PAGE; + $pluginrenderer = $PAGE->get_renderer('mod_bigbluebuttonbn'); + $groupselector = $pluginrenderer->render_groups_selector($this->instance); + if (method_exists($output, 'render_groups_selector')) { + // If the output renderer supports the method, override it. + $groupselector = $output->render_groups_selector($this->instance); + } $pollinterval = bigbluebutton_proxy::get_poll_interval(); $templatedata = (object) [ 'instanceid' => $this->instance->get_instance_id(), 'pollinterval' => $pollinterval * 1000, // Javascript poll interval is in miliseconds. - 'groupselector' => $output->render_groups_selector($this->instance), + 'groupselector' => $groupselector, 'meetingname' => $this->instance->get_meeting_name(), 'description' => $this->instance->get_meeting_description(true), 'joinurl' => $this->instance->get_join_url(), @@ -145,5 +153,4 @@ class view_page implements renderable, templatable { return false; } - } diff --git a/public/mod/bigbluebuttonbn/tests/behat/subplugins.feature b/public/mod/bigbluebuttonbn/tests/behat/subplugins.feature index ba41a0a06e3..c2a1678f519 100644 --- a/public/mod/bigbluebuttonbn/tests/behat/subplugins.feature +++ b/public/mod/bigbluebuttonbn/tests/behat/subplugins.feature @@ -1,4 +1,4 @@ -@mod @mod_bigbluebuttonbn @with_bbbext_simple +@mod @mod_bigbluebuttonbn @with_bbbext_simple @with_bbbext_complex Feature: BigBlueButtonBN Subplugins test As a BigBlueButtonBN user I can list the subplugins the admin settings pages @@ -137,3 +137,13 @@ Feature: BigBlueButtonBN Subplugins test And I am on the "BBB Instance name" "bigbluebuttonbn activity" page logged in as "admin" Then I should see "Override Navigation" And I should not see "Append Navigation" + + @javascript + Scenario: I check that subplugins can override the view + Given I log in as "admin" + And I am on the "BBB Instance name" "bigbluebuttonbn activity" page logged in as "admin" + And I should not see "Hello from complex::renderer!" + And I navigate to "Plugins > Activity modules > BigBlueButton > Manage BigBlueButton extension plugins" in site administration + And I click on "Enable" "link" in the "Complex" "table_row" + When I am on the "BBB Instance name" "bigbluebuttonbn activity" page logged in as "admin" + And I should see "Hello from complex::renderer!" diff --git a/public/mod/bigbluebuttonbn/tests/fixtures/extension/complex/classes/bigbluebuttonbn/view_page_addons.php b/public/mod/bigbluebuttonbn/tests/fixtures/extension/complex/classes/bigbluebuttonbn/view_page_addons.php new file mode 100644 index 00000000000..5d07f3d6ca1 --- /dev/null +++ b/public/mod/bigbluebuttonbn/tests/fixtures/extension/complex/classes/bigbluebuttonbn/view_page_addons.php @@ -0,0 +1,56 @@ +. + +namespace bbbext_complex\bigbluebuttonbn; + +use stdClass; +use mod_bigbluebuttonbn\instance; + +/** + * View Page template renderable. + * + * @package mod_bigbluebuttonbn + * @copyright 2025 onwards, Blindside Networks Inc + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) + */ +class view_page_addons extends \mod_bigbluebuttonbn\local\extension\view_page_addons { + /** @var instance The instance being rendered */ + protected $instance; + + /** + * Constructor for the View Page. + * + * @param instance $instance + */ + public function __construct(instance $instance) { + $this->instance = $instance; + } + + /** + * Export the content required to render the template. + * + * @param mixed $renderer The renderer instance (matches parent signature). + * @return stdClass + */ + public function export_for_template($renderer): \stdClass { + return (object) [ + 'message' => 'Hello from complex::renderer!', + 'meetingname' => $this->instance->get_meeting_name(), + 'description' => $this->instance->get_meeting_description(true), + ]; + } +} diff --git a/public/mod/bigbluebuttonbn/tests/fixtures/extension/complex/templates/view_page_addons.mustache b/public/mod/bigbluebuttonbn/tests/fixtures/extension/complex/templates/view_page_addons.mustache new file mode 100644 index 00000000000..ba6bb353bcf --- /dev/null +++ b/public/mod/bigbluebuttonbn/tests/fixtures/extension/complex/templates/view_page_addons.mustache @@ -0,0 +1,46 @@ +{{! + 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 bbbext_complex/view_page + + This template renders the /view_page.php page. + + Example context (json): + { + "instanceid": 1234, + "meetingname": "My first meeting", + "meetingdescription": "This is my first meeting!", + "serverwarning": true, + "sitenotification": { + "message": "Unlock premium feature", + "actions": [ + { + "url": "https://example.com/", + "name": "action", + "value": "buy", + "title": "Upgrade now" + } + ] + }, + "pollinterval": 5 + } + +}} +

View Page

+
+ {{message}} +
diff --git a/public/mod/bigbluebuttonbn/view.php b/public/mod/bigbluebuttonbn/view.php index 74175cddd1c..fa50dae8909 100644 --- a/public/mod/bigbluebuttonbn/view.php +++ b/public/mod/bigbluebuttonbn/view.php @@ -25,6 +25,7 @@ * @author Darko Miletic (darko.miletic [at] gmail [dt] com) */ +use mod_bigbluebuttonbn\extension; use mod_bigbluebuttonbn\instance; use mod_bigbluebuttonbn\local\config; use mod_bigbluebuttonbn\local\exceptions\server_not_available_exception; @@ -81,7 +82,11 @@ $PAGE->set_heading($course->fullname); $renderer = $PAGE->get_renderer('mod_bigbluebuttonbn'); try { - $renderedinfo = $renderer->render(new view_page($instance)); + $renderedinfo = extension::get_rendered_output_override($renderer, $instance); + if (!$renderedinfo) { + // If no override is found, use the default view_page renderable. + $renderedinfo = $renderer->render(new view_page($instance)); + } } catch (server_not_available_exception $e) { bigbluebutton_proxy::handle_server_not_available($instance); }