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
parent
17162f32ef
commit
2a53b7bb7b
|
@ -3692,12 +3692,24 @@ class H5PContentValidator {
|
||||||
$value = NULL;
|
$value = NULL;
|
||||||
return;
|
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;
|
$message = NULL;
|
||||||
// Create an understandable error message:
|
// Create an understandable error message:
|
||||||
$machineNameArray = explode(' ', $value->library);
|
$machineNameArray = explode(' ', $value->library);
|
||||||
$machineName = $machineNameArray[0];
|
$machineName = $machineNameArray[0];
|
||||||
foreach ($semantics->options as $semanticsLibrary) {
|
foreach ($libraryNames as $semanticsLibrary) {
|
||||||
$semanticsMachineNameArray = explode(' ', $semanticsLibrary);
|
$semanticsMachineNameArray = explode(' ', $semanticsLibrary);
|
||||||
$semanticsMachineName = $semanticsMachineNameArray[0];
|
$semanticsMachineName = $semanticsMachineNameArray[0];
|
||||||
if ($machineName === $semanticsMachineName) {
|
if ($machineName === $semanticsMachineName) {
|
||||||
|
@ -3741,6 +3753,7 @@ class H5PContentValidator {
|
||||||
if (isset($semantics->extraAttributes)) {
|
if (isset($semantics->extraAttributes)) {
|
||||||
$validKeys = array_merge($validKeys, $semantics->extraAttributes);
|
$validKeys = array_merge($validKeys, $semantics->extraAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->filterParams($value, $validKeys);
|
$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)) {
|
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);
|
unset($value->subContentId);
|
||||||
|
|
Loading…
Reference in New Issue