From bc72a54cb17e9b9d399e99f89ef64ba59b9d412a Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 16 Oct 2019 17:44:49 +0200 Subject: [PATCH] MDL-65400 block: Support returning settings for core blocks --- .../block_activity_results.php | 17 ++++++++++++++ blocks/blog_recent/block_blog_recent.php | 16 ++++++++++++++ blocks/blog_tags/block_blog_tags.php | 16 ++++++++++++++ blocks/course_list/block_course_list.php | 21 ++++++++++++++++++ .../glossary_random/block_glossary_random.php | 16 ++++++++++++++ blocks/html/block_html.php | 19 ++++++++++++++++ blocks/mentees/block_mentees.php | 16 ++++++++++++++ blocks/myoverview/block_myoverview.php | 16 ++++++++++++++ blocks/myprofile/block_myprofile.php | 15 +++++++++++++ blocks/navigation/block_navigation.php | 16 ++++++++++++++ blocks/online_users/block_online_users.php | 21 ++++++++++++++++++ .../block_recentlyaccessedcourses.php | 16 ++++++++++++++ blocks/rss_client/block_rss_client.php | 22 +++++++++++++++++++ blocks/section_links/block_section_links.php | 17 ++++++++++++++ blocks/settings/block_settings.php | 16 ++++++++++++++ .../starredcourses/block_starredcourses.php | 16 ++++++++++++++ blocks/tag_flickr/block_tag_flickr.php | 16 ++++++++++++++ blocks/tag_youtube/block_tag_youtube.php | 20 +++++++++++++++++ blocks/tags/block_tags.php | 16 ++++++++++++++ 19 files changed, 328 insertions(+) diff --git a/blocks/activity_results/block_activity_results.php b/blocks/activity_results/block_activity_results.php index 2890415efb559..f62b43048c305 100644 --- a/blocks/activity_results/block_activity_results.php +++ b/blocks/activity_results/block_activity_results.php @@ -704,4 +704,21 @@ private function get_scale($scaleid) { return $scale; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $instanceconfigs = !empty($this->config) ? $this->config : new stdClass(); + $pluginconfigs = get_config('block_activity_results'); + + return (object) [ + 'instance' => $instanceconfigs, + 'plugin' => $pluginconfigs, + ]; + } } diff --git a/blocks/blog_recent/block_blog_recent.php b/blocks/blog_recent/block_blog_recent.php index 80befebffecff..b0d875b789da1 100644 --- a/blocks/blog_recent/block_blog_recent.php +++ b/blocks/blog_recent/block_blog_recent.php @@ -125,4 +125,20 @@ function get_content() { $this->content->text .= get_string('norecentblogentries', 'block_blog_recent'); } } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = !empty($this->config) ? $this->config : new stdClass(); + + return (object) [ + 'instance' => $configs, + 'plugin' => new stdClass(), + ]; + } } diff --git a/blocks/blog_tags/block_blog_tags.php b/blocks/blog_tags/block_blog_tags.php index f46bd417bf074..f479e3896f661 100644 --- a/blocks/blog_tags/block_blog_tags.php +++ b/blocks/blog_tags/block_blog_tags.php @@ -206,6 +206,22 @@ function get_content() { } return $this->content; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = !empty($this->config) ? $this->config : new stdClass(); + + return (object) [ + 'instance' => $configs, + 'plugin' => new stdClass(), + ]; + } } function block_blog_tags_sort($a, $b) { diff --git a/blocks/course_list/block_course_list.php b/blocks/course_list/block_course_list.php index b4aa2c1edaad9..0c4b83227634e 100644 --- a/blocks/course_list/block_course_list.php +++ b/blocks/course_list/block_course_list.php @@ -177,6 +177,27 @@ function get_remote_courses() { public function get_aria_role() { return 'navigation'; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + global $CFG; + + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = (object) [ + 'adminview' => $CFG->block_course_list_adminview, + 'hideallcourseslink' => $CFG->block_course_list_hideallcourseslink + ]; + + return (object) [ + 'instance' => new stdClass(), + 'plugin' => $configs, + ]; + } } diff --git a/blocks/glossary_random/block_glossary_random.php b/blocks/glossary_random/block_glossary_random.php index 5f15e8e082b29..42a6ebc357578 100644 --- a/blocks/glossary_random/block_glossary_random.php +++ b/blocks/glossary_random/block_glossary_random.php @@ -254,5 +254,21 @@ function get_content() { return $this->content; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = !empty($this->config) ? $this->config : new stdClass(); + + return (object) [ + 'instance' => $configs, + 'plugin' => new stdClass(), + ]; + } } diff --git a/blocks/html/block_html.php b/blocks/html/block_html.php index 954a8099fb76e..cb1f6a6b7990c 100644 --- a/blocks/html/block_html.php +++ b/blocks/html/block_html.php @@ -209,4 +209,23 @@ function html_attributes() { return $attributes; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + global $CFG; + + // Return all settings for all users since it is safe (no private keys, etc..). + $instanceconfigs = !empty($this->config) ? $this->config : new stdClass(); + $pluginconfigs = (object) ['allowcssclasses' => $CFG->block_html_allowcssclasses]; + + return (object) [ + 'instance' => $instanceconfigs, + 'plugin' => $pluginconfigs, + ]; + } } diff --git a/blocks/mentees/block_mentees.php b/blocks/mentees/block_mentees.php index 0c2ff91557508..ff326308ef46a 100644 --- a/blocks/mentees/block_mentees.php +++ b/blocks/mentees/block_mentees.php @@ -78,5 +78,21 @@ function get_content() { public function instance_can_be_docked() { return parent::instance_can_be_docked() && isset($this->config->title) && !empty($this->config->title); } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = !empty($this->config) ? $this->config : new stdClass(); + + return (object) [ + 'instance' => $configs, + 'plugin' => new stdClass(), + ]; + } } diff --git a/blocks/myoverview/block_myoverview.php b/blocks/myoverview/block_myoverview.php index 3a7dd138c422f..db02741b00ad4 100644 --- a/blocks/myoverview/block_myoverview.php +++ b/blocks/myoverview/block_myoverview.php @@ -82,5 +82,21 @@ public function applicable_formats() { public function has_config() { return true; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = get_config('block_myoverview'); + + return (object) [ + 'instance' => new stdClass(), + 'plugin' => $configs, + ]; + } } diff --git a/blocks/myprofile/block_myprofile.php b/blocks/myprofile/block_myprofile.php index 4b9013fa5df43..db869724e1681 100644 --- a/blocks/myprofile/block_myprofile.php +++ b/blocks/myprofile/block_myprofile.php @@ -129,4 +129,19 @@ public function after_install() { public function before_delete() { } + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = !empty($this->config) ? $this->config : new stdClass(); + + return (object) [ + 'instance' => $configs, + 'plugin' => new stdClass(), + ]; + } } diff --git a/blocks/navigation/block_navigation.php b/blocks/navigation/block_navigation.php index 76a4c3f9be881..b8080b427c60f 100644 --- a/blocks/navigation/block_navigation.php +++ b/blocks/navigation/block_navigation.php @@ -326,4 +326,20 @@ protected function trim_center($string, $length) { public function get_aria_role() { return 'navigation'; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = !empty($this->config) ? $this->config : new stdClass(); + + return (object) [ + 'instance' => $configs, + 'plugin' => new stdClass(), + ]; + } } diff --git a/blocks/online_users/block_online_users.php b/blocks/online_users/block_online_users.php index 9d1fc90b7f968..dbdf802097b5f 100644 --- a/blocks/online_users/block_online_users.php +++ b/blocks/online_users/block_online_users.php @@ -157,6 +157,27 @@ function get_content() { return $this->content; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + global $CFG; + + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = (object) [ + 'timetosee' => $CFG->block_online_users_timetosee, + 'onlinestatushiding' => $CFG->block_online_users_onlinestatushiding + ]; + + return (object) [ + 'instance' => new stdClass(), + 'plugin' => $configs, + ]; + } } diff --git a/blocks/recentlyaccessedcourses/block_recentlyaccessedcourses.php b/blocks/recentlyaccessedcourses/block_recentlyaccessedcourses.php index 0c8c388d73714..58241a8598570 100644 --- a/blocks/recentlyaccessedcourses/block_recentlyaccessedcourses.php +++ b/blocks/recentlyaccessedcourses/block_recentlyaccessedcourses.php @@ -76,4 +76,20 @@ public function applicable_formats() { public function has_config() { return true; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = get_config('block_recentlyaccessedcourses'); + + return (object) [ + 'instance' => new stdClass(), + 'plugin' => $configs, + ]; + } } diff --git a/blocks/rss_client/block_rss_client.php b/blocks/rss_client/block_rss_client.php index 3b330490a321b..06052c735c347 100644 --- a/blocks/rss_client/block_rss_client.php +++ b/blocks/rss_client/block_rss_client.php @@ -279,4 +279,26 @@ function format_title($title,$max=64) { return core_text::substr($title, 0, $max - 3) . '...'; } } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + global $CFG; + + // Return all settings for all users since it is safe (no private keys, etc..). + $instanceconfigs = !empty($this->config) ? $this->config : new stdClass(); + $pluginconfigs = (object) [ + 'num_entries' => $CFG->block_rss_client_num_entries, + 'timeout' => $CFG->block_rss_client_timeout + ]; + + return (object) [ + 'instance' => $instanceconfigs, + 'plugin' => $pluginconfigs, + ]; + } } diff --git a/blocks/section_links/block_section_links.php b/blocks/section_links/block_section_links.php index 7f1268330696b..6c638ea47da83 100644 --- a/blocks/section_links/block_section_links.php +++ b/blocks/section_links/block_section_links.php @@ -154,6 +154,23 @@ public function instance_allow_config() { public function has_config() { return true; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $instanceconfigs = !empty($this->config) ? $this->config : new stdClass(); + $pluginconfigs = get_config('block_section_links'); + + return (object) [ + 'instance' => $instanceconfigs, + 'plugin' => $pluginconfigs, + ]; + } } diff --git a/blocks/settings/block_settings.php b/blocks/settings/block_settings.php index 1ed9409713ed1..96f79f9f8a309 100644 --- a/blocks/settings/block_settings.php +++ b/blocks/settings/block_settings.php @@ -160,4 +160,20 @@ function get_content() { public function get_aria_role() { return 'navigation'; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = !empty($this->config) ? $this->config : new stdClass(); + + return (object) [ + 'instance' => $configs, + 'plugin' => new stdClass(), + ]; + } } diff --git a/blocks/starredcourses/block_starredcourses.php b/blocks/starredcourses/block_starredcourses.php index 46bfda9aa1ef5..365435a55889b 100644 --- a/blocks/starredcourses/block_starredcourses.php +++ b/blocks/starredcourses/block_starredcourses.php @@ -81,4 +81,20 @@ public function applicable_formats() { public function has_config() { return true; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = get_config('block_starredcourses'); + + return (object) [ + 'instance' => new stdClass(), + 'plugin' => $configs, + ]; + } } diff --git a/blocks/tag_flickr/block_tag_flickr.php b/blocks/tag_flickr/block_tag_flickr.php index 22471f38eb1e3..affb9dea587cc 100644 --- a/blocks/tag_flickr/block_tag_flickr.php +++ b/blocks/tag_flickr/block_tag_flickr.php @@ -178,6 +178,22 @@ function build_photo_url ($photo, $size='medium') { } return $url; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = !empty($this->config) ? $this->config : new stdClass(); + + return (object) [ + 'instance' => $configs, + 'plugin' => new stdClass(), + ]; + } } diff --git a/blocks/tag_youtube/block_tag_youtube.php b/blocks/tag_youtube/block_tag_youtube.php index 9c79fe8d982dd..51a33d57f1ba8 100644 --- a/blocks/tag_youtube/block_tag_youtube.php +++ b/blocks/tag_youtube/block_tag_youtube.php @@ -398,5 +398,25 @@ function category_map_old2new($oldcat) { return $oldcat; } } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // There is a private key, only admins can see it. + $pluginconfigs = get_config('block_tag_youtube'); + if (!has_capability('moodle/site:config', context_system::instance())) { + unset($pluginconfigs->apikey); + } + $instanceconfigs = !empty($this->config) ? $this->config : new stdClass(); + + return (object) [ + 'instance' => $instanceconfigs, + 'plugin' => $pluginconfigs, + ]; + } } diff --git a/blocks/tags/block_tags.php b/blocks/tags/block_tags.php index f263ddf86de48..b0a07d9316264 100644 --- a/blocks/tags/block_tags.php +++ b/blocks/tags/block_tags.php @@ -109,4 +109,20 @@ public function get_content() { return $this->content; } + + /** + * Return the plugin config settings for external functions. + * + * @return stdClass the configs for both the block instance and plugin + * @since Moodle 3.8 + */ + public function get_config_for_external() { + // Return all settings for all users since it is safe (no private keys, etc..). + $configs = !empty($this->config) ? $this->config : new stdClass(); + + return (object) [ + 'instance' => $configs, + 'plugin' => new stdClass(), + ]; + } }