mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
MDL-64820 core: Exporter read_definition
Modified the read_properties_definition to recursively check and set the default array values expected.
This commit is contained in:
parent
3271c39c74
commit
432cdac4bd
2 changed files with 29 additions and 4 deletions
24
lib/classes/external/exporter.php
vendored
24
lib/classes/external/exporter.php
vendored
|
@ -261,16 +261,32 @@ abstract class exporter {
|
|||
final public static function read_properties_definition() {
|
||||
$properties = static::properties_definition();
|
||||
$customprops = static::define_other_properties();
|
||||
foreach ($customprops as $property => $definition) {
|
||||
$customprops = static::format_properties($customprops);
|
||||
$properties += $customprops;
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively formats a given property definition with the default fields required.
|
||||
*
|
||||
* @param array $properties List of properties to format
|
||||
* @return array Formatted array
|
||||
*/
|
||||
final public static function format_properties($properties) {
|
||||
foreach ($properties as $property => $definition) {
|
||||
// Ensures that null is set to its default.
|
||||
if (!isset($definition['null'])) {
|
||||
$customprops[$property]['null'] = NULL_NOT_ALLOWED;
|
||||
$properties[$property]['null'] = NULL_NOT_ALLOWED;
|
||||
}
|
||||
if (!isset($definition['description'])) {
|
||||
$customprops[$property]['description'] = $property;
|
||||
$properties[$property]['description'] = $property;
|
||||
}
|
||||
|
||||
// If an array is provided, it may be a nested array that is unformatted so rinse and repeat.
|
||||
if (is_array($definition['type'])) {
|
||||
$properties[$property]['type'] = static::format_properties($definition['type']);
|
||||
}
|
||||
}
|
||||
$properties += $customprops;
|
||||
return $properties;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue