Merge branch 'MDL-65400-master' of git://github.com/jleyva/moodle

This commit is contained in:
Jake Dallimore 2019-10-24 09:28:31 +08:00
commit ebca610a44
23 changed files with 389 additions and 0 deletions

View File

@ -704,4 +704,21 @@ class block_activity_results extends block_base {
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,
];
}
}

View File

@ -125,4 +125,20 @@ class block_blog_recent extends block_base {
$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(),
];
}
}

View File

@ -206,6 +206,22 @@ class block_blog_tags extends block_base {
}
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) {

View File

@ -67,6 +67,16 @@ class core_block_external extends external_api {
),
'Block contents (if required).', VALUE_OPTIONAL
),
'configs' => new external_multiple_structure(
new external_single_structure(
array(
'name' => new external_value(PARAM_RAW, 'Name.'),
'value' => new external_value(PARAM_RAW, 'Value.'),
'type' => new external_value(PARAM_ALPHA, 'Type (instance or plugin).'),
)
),
'Block instance and plugin configuration settings.', VALUE_OPTIONAL
),
), 'Block information.'
);
}
@ -110,6 +120,17 @@ class core_block_external extends external_api {
if ($returncontents) {
$block['contents'] = (array) $blockinstances[$bc->blockinstanceid]->get_content_for_external($OUTPUT);
}
$configs = (array) $blockinstances[$bc->blockinstanceid]->get_config_for_external();
foreach ($configs as $type => $data) {
foreach ((array) $data as $name => $value) {
$block['configs'][] = [
'name' => $name,
'value' => $value,
'type' => $type,
];
}
}
$allblocks[] = $block;
}
}

View File

@ -177,6 +177,27 @@ class block_course_list extends block_list {
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,
];
}
}

View File

@ -254,5 +254,21 @@ class block_glossary_random extends block_base {
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(),
];
}
}

View File

@ -209,4 +209,23 @@ class block_html extends block_base {
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,
];
}
}

View File

@ -78,5 +78,21 @@ class block_mentees extends block_base {
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(),
];
}
}

View File

@ -305,6 +305,21 @@ class block_base {
return $bc;
}
/**
* Return the plugin config settings for external functions.
*
* In some cases the configs will need formatting or be returned only if the current user has some capabilities enabled.
*
* @return stdClass the configs for both the block instance and plugin (as object with name -> value)
* @since Moodle 3.8
*/
public function get_config_for_external() {
return (object) [
'instance' => new stdClass(),
'plugin' => new stdClass(),
];
}
/**
* Convert the contents of the block to HTML.
*

View File

@ -82,5 +82,21 @@ class block_myoverview extends block_base {
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,
];
}
}

View File

@ -129,4 +129,19 @@ class block_myprofile extends block_base {
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(),
];
}
}

View File

@ -326,4 +326,20 @@ class block_navigation extends block_base {
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(),
];
}
}

View File

@ -157,6 +157,27 @@ class block_online_users extends block_base {
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,
];
}
}

View File

@ -76,4 +76,20 @@ class block_recentlyaccessedcourses extends block_base {
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,
];
}
}

View File

@ -279,4 +279,26 @@
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,
];
}
}

View File

@ -154,6 +154,23 @@ class block_section_links extends block_base {
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,
];
}
}

View File

@ -160,4 +160,20 @@ class block_settings extends block_base {
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(),
];
}
}

View File

@ -81,4 +81,20 @@ class block_starredcourses extends block_base {
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,
];
}
}

View File

@ -178,6 +178,22 @@ class block_tag_flickr extends block_base {
}
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(),
];
}
}

View File

@ -398,5 +398,25 @@ class block_tag_youtube extends block_base {
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,
];
}
}

View File

@ -109,4 +109,20 @@ class block_tags extends block_base {
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(),
];
}
}

View File

@ -213,6 +213,19 @@ class core_block_externallib_testcase extends externallib_advanced_testcase {
$this->assertEquals('', $result['blocks'][0]['contents']['footer']);
$this->assertCount(1, $result['blocks'][0]['contents']['files']);
$this->assertEquals($newblock, $result['blocks'][0]['name']);
$configcounts = 0;
foreach ($result['blocks'][0]['configs'] as $config) {
if ($config['type'] = 'plugin' && $config['name'] == 'allowcssclasses' && $config['value'] == 0) {
$configcounts++;
} else if ($config['type'] = 'instance' && $config['name'] == 'text' && $config['value'] == $body) {
$configcounts++;
} else if ($config['type'] = 'instance' && $config['name'] == 'title' && $config['value'] == $title) {
$configcounts++;
} else if ($config['type'] = 'instance' && $config['name'] == 'format' && $config['value'] == 0) {
$configcounts++;
}
}
$this->assertEquals(4, $configcounts);
}
/**
@ -225,6 +238,9 @@ class core_block_externallib_testcase extends externallib_advanced_testcase {
$user = $this->getDataGenerator()->create_user();
$PAGE->set_url('/my/index.php'); // Need this because some internal API calls require the $PAGE url to be set.
// Force a setting change to check the returned blocks settings.
set_config('displaycategories', 0, 'block_recentlyaccessedcourses');
// Get the expected default blocks.
$alldefaultblocksordered = $DB->get_records_menu('block_instances',
array('pagetypepattern' => 'my-index'), 'defaultregion, defaultweight ASC', 'id, blockname');
@ -242,6 +258,12 @@ class core_block_externallib_testcase extends externallib_advanced_testcase {
// Check all the returned blocks are in the expected blocks array.
$this->assertContains($block['name'], $alldefaultblocksordered);
$returnedblocks[] = $block['name'];
// Check the configuration returned for this default block.
if ($block['name'] == 'recentlyaccessedcourses') {
$this->assertEquals('displaycategories', $block['configs'][0]['name']);
$this->assertEquals(0, $block['configs'][0]['value']);
$this->assertEquals('plugin', $block['configs'][0]['type']);
}
}
// Remove lp block.
array_shift($alldefaultblocksordered);

View File

@ -4,6 +4,9 @@ information provided here is intended especially for developers.
=== 3.8 ===
* Block block_community is no longer a part of core.
* Block block_participants is no longer a part of core.
* Block plugins should overwrite get_config_for_external function to return the blocks settings viewable by the current user.
If the block plugin does not have any setting that could be considerated private (like a private/access key/token),
is ok to return all the settings via the get_config_for_external function.
=== 3.7 ===
* The block:addinstance capability is no longer required if the block can only be added to a dashboard.