Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
c9acdfb6
Commit
c9acdfb6
authored
Oct 16, 2019
by
Juan Leyva
Browse files
MDL-65400 block: Support getting block settings via WS
parent
aaff6692
Changes
4
Hide whitespace changes
Inline
Side-by-side
blocks/classes/external.php
View file @
c9acdfb6
...
@@ -67,6 +67,16 @@ class core_block_external extends external_api {
...
@@ -67,6 +67,16 @@ class core_block_external extends external_api {
),
),
'Block contents (if required).'
,
VALUE_OPTIONAL
'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.'
),
'Block information.'
);
);
}
}
...
@@ -110,6 +120,17 @@ class core_block_external extends external_api {
...
@@ -110,6 +120,17 @@ class core_block_external extends external_api {
if
(
$returncontents
)
{
if
(
$returncontents
)
{
$block
[
'contents'
]
=
(
array
)
$blockinstances
[
$bc
->
blockinstanceid
]
->
get_content_for_external
(
$OUTPUT
);
$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
;
$allblocks
[]
=
$block
;
}
}
}
}
...
...
blocks/moodleblock.class.php
View file @
c9acdfb6
...
@@ -305,6 +305,21 @@ class block_base {
...
@@ -305,6 +305,21 @@ class block_base {
return
$bc
;
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.
* Convert the contents of the block to HTML.
*
*
...
...
blocks/tests/externallib_test.php
View file @
c9acdfb6
...
@@ -213,6 +213,19 @@ class core_block_externallib_testcase extends externallib_advanced_testcase {
...
@@ -213,6 +213,19 @@ class core_block_externallib_testcase extends externallib_advanced_testcase {
$this
->
assertEquals
(
''
,
$result
[
'blocks'
][
0
][
'contents'
][
'footer'
]);
$this
->
assertEquals
(
''
,
$result
[
'blocks'
][
0
][
'contents'
][
'footer'
]);
$this
->
assertCount
(
1
,
$result
[
'blocks'
][
0
][
'contents'
][
'files'
]);
$this
->
assertCount
(
1
,
$result
[
'blocks'
][
0
][
'contents'
][
'files'
]);
$this
->
assertEquals
(
$newblock
,
$result
[
'blocks'
][
0
][
'name'
]);
$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 {
...
@@ -225,6 +238,9 @@ class core_block_externallib_testcase extends externallib_advanced_testcase {
$user
=
$this
->
getDataGenerator
()
->
create_user
();
$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.
$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.
// Get the expected default blocks.
$alldefaultblocksordered
=
$DB
->
get_records_menu
(
'block_instances'
,
$alldefaultblocksordered
=
$DB
->
get_records_menu
(
'block_instances'
,
array
(
'pagetypepattern'
=>
'my-index'
),
'defaultregion, defaultweight ASC'
,
'id, blockname'
);
array
(
'pagetypepattern'
=>
'my-index'
),
'defaultregion, defaultweight ASC'
,
'id, blockname'
);
...
@@ -242,6 +258,12 @@ class core_block_externallib_testcase extends externallib_advanced_testcase {
...
@@ -242,6 +258,12 @@ class core_block_externallib_testcase extends externallib_advanced_testcase {
// Check all the returned blocks are in the expected blocks array.
// Check all the returned blocks are in the expected blocks array.
$this
->
assertContains
(
$block
[
'name'
],
$alldefaultblocksordered
);
$this
->
assertContains
(
$block
[
'name'
],
$alldefaultblocksordered
);
$returnedblocks
[]
=
$block
[
'name'
];
$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.
// Remove lp block.
array_shift
(
$alldefaultblocksordered
);
array_shift
(
$alldefaultblocksordered
);
...
...
blocks/upgrade.txt
View file @
c9acdfb6
...
@@ -4,6 +4,9 @@ information provided here is intended especially for developers.
...
@@ -4,6 +4,9 @@ information provided here is intended especially for developers.
=== 3.8 ===
=== 3.8 ===
* Block block_community is no longer a part of core.
* Block block_community is no longer a part of core.
* Block block_participants 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 ===
=== 3.7 ===
* The block:addinstance capability is no longer required if the block can only be added to a dashboard.
* The block:addinstance capability is no longer required if the block can only be added to a dashboard.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment