From 2a53b7bb7b11f1d89239c38e1a85661c183cd210 Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Fri, 22 Jun 2018 13:45:59 +0200 Subject: [PATCH] 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" --- h5p.classes.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 09f15ed..2d1c5e9 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -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);