From c1720141fda8bb2cdfbfdd36992e07669972c2f1 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Fri, 19 Oct 2018 11:27:57 +0200 Subject: [PATCH] MDL-63708 tool_mobile: Add options for disabling blocks Now that we are supporting the new dashboard and site home blocks on the mobile app, we need options to allow admin to forbid certain blocks to be displayed on the app. --- admin/tool/mobile/classes/api.php | 21 ++++++++++++++++++++ admin/tool/mobile/tests/externallib_test.php | 2 ++ 2 files changed, 23 insertions(+) diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php index 5fcd7f7879e..71cf2bb8944 100644 --- a/admin/tool/mobile/classes/api.php +++ b/admin/tool/mobile/classes/api.php @@ -336,6 +336,7 @@ class api { $mainmenu = new lang_string('mainmenu', 'tool_mobile'); $course = new lang_string('course'); $modules = new lang_string('managemodules'); + $blocks = new lang_string('blocks'); $user = new lang_string('user'); $files = new lang_string('files'); $remoteaddons = new lang_string('remoteaddons', 'tool_mobile'); @@ -359,6 +360,25 @@ class api { } + // Display blocks. + $availableblocks = core_plugin_manager::instance()->get_plugins_of_type('block'); + $courseblocks = array(); + $appsupportedblocks = array( + 'activity_modules' => 'CoreBlockDelegate_AddonBlockActivityModules', + 'site_main_menu' => 'CoreBlockDelegate_AddonBlockSiteMainMenu', + 'myoverview' => 'CoreBlockDelegate_AddonBlockMyOverview', + 'timeline' => 'CoreBlockDelegate_AddonBlockTimeline', + 'recentlyaccessedcourses' => 'CoreBlockDelegate_AddonBlockRecentlyAccessedCourses', + 'starredcourses' => 'CoreBlockDelegate_AddonBlockStarredCourses', + 'recentlyaccesseditems' => 'CoreBlockDelegate_AddonBlockRecentlyAccessedItems', + ); + + foreach ($availableblocks as $block) { + if (isset($appsupportedblocks[$block->name])) { + $courseblocks[$appsupportedblocks[$block->name]] = $block->displayname; + } + } + $features = array( 'NoDelegate_CoreOffline' => new lang_string('offlineuse', 'tool_mobile'), '$mmLoginEmailSignup' => new lang_string('startsignup'), @@ -401,6 +421,7 @@ class api { 'files_upload' => new lang_string('upload'), ), "$modules" => $coursemodules, + "$blocks" => $courseblocks, ); if (!empty($remoteaddonslist)) { diff --git a/admin/tool/mobile/tests/externallib_test.php b/admin/tool/mobile/tests/externallib_test.php index d5a8a344758..00db97ef5ca 100644 --- a/admin/tool/mobile/tests/externallib_test.php +++ b/admin/tool/mobile/tests/externallib_test.php @@ -109,6 +109,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase { set_config('agedigitalconsentverification', 1); set_config('autolang', 1); set_config('lang', 'a_b'); // Set invalid lang. + set_config('disabledfeatures', 'myoverview', 'tool_mobile'); list($authinstructions, $notusedformat) = external_format_text($authinstructions, FORMAT_MOODLE, $context->id); $expected['registerauth'] = 'email'; @@ -120,6 +121,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase { $expected['supportemail'] = $CFG->supportemail; $expected['autolang'] = '1'; $expected['lang'] = ''; // Expect empty because it was set to an invalid lang. + $expected['tool_mobile_disabledfeatures'] = 'myoverview'; if ($logourl = $OUTPUT->get_logo_url()) { $expected['logourl'] = $logourl->out(false);