HFP-2059 Accept objects as library options, too

Compound content types should be able to deactivate the metadata
button for their subcontent types. This should be achievable
by amending the options property of a library field.

The options array can not either contains strings with library names
or objects with the property "name" (mandatory) and further properties,
one of them being "hasmetadata"
pull/52/head
Oliver Tacke 2018-06-22 13:45:59 +02:00
parent 17162f32ef
commit 2a53b7bb7b
1 changed files with 15 additions and 2 deletions

View File

@ -3692,12 +3692,24 @@ class H5PContentValidator {
$value = NULL;
return;
}
if (!in_array($value->library, $semantics->options)) {
// Check for array of objects or array of strings
if (is_object($semantics->options[0])) {
$getLibraryNames = function ($item) {
return $item->name;
};
$libraryNames = array_map($getLibraryNames, $semantics->options);
}
else {
$libraryNames = $semantics->options;
}
if (!in_array($value->library, $libraryNames)) {
$message = NULL;
// Create an understandable error message:
$machineNameArray = explode(' ', $value->library);
$machineName = $machineNameArray[0];
foreach ($semantics->options as $semanticsLibrary) {
foreach ($libraryNames as $semanticsLibrary) {
$semanticsMachineNameArray = explode(' ', $semanticsLibrary);
$semanticsMachineName = $semanticsMachineNameArray[0];
if ($machineName === $semanticsMachineName) {
@ -3741,6 +3753,7 @@ class H5PContentValidator {
if (isset($semantics->extraAttributes)) {
$validKeys = array_merge($validKeys, $semantics->extraAttributes);
}
$this->filterParams($value, $validKeys);
if (isset($value->subContentId) && ! preg_match('/^\{?[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\}?$/', $value->subContentId)) {
unset($value->subContentId);