JI-857 Validate metadata properly

HFP-2095-Fix-table-styling
Paal Joergensen 2018-10-04 16:02:05 +02:00
parent e75745f0db
commit 9081ca3128
1 changed files with 6 additions and 3 deletions

View File

@ -1947,7 +1947,7 @@ class H5PCore {
if ($content !== NULL) { if ($content !== NULL) {
// Validate main content's metadata // Validate main content's metadata
$validator = new H5PContentValidator($this->h5pF, $this); $validator = new H5PContentValidator($this->h5pF, $this);
$validator->validateMetadata($content['metadata']); $content['metadata'] = $validator->validateMetadata($content['metadata']);
$content['library'] = array( $content['library'] = array(
'id' => $content['libraryId'], 'id' => $content['libraryId'],
@ -3384,8 +3384,9 @@ class H5PContentValidator {
* Validate metadata * Validate metadata
* *
* @param array $metadata * @param array $metadata
* @return array Validated & filtered
*/ */
public function validateMetadata(&$metadata) { public function validateMetadata($metadata) {
$semantics = $this->getMetadataSemantics(); $semantics = $this->getMetadataSemantics();
$group = (object)$metadata; $group = (object)$metadata;
@ -3393,6 +3394,8 @@ class H5PContentValidator {
'type' => 'group', 'type' => 'group',
'fields' => $semantics, 'fields' => $semantics,
), FALSE); ), FALSE);
return (array)$group;
} }
/** /**
@ -3919,7 +3922,7 @@ class H5PContentValidator {
// Validate subcontent's metadata // Validate subcontent's metadata
if (isset($value->metadata)) { if (isset($value->metadata)) {
$this->validateMetadata($value->metadata); $value->metadata = $this->validateMetadata($value->metadata);
} }
$validKeys = array('library', 'params', 'subContentId', 'metadata'); $validKeys = array('library', 'params', 'subContentId', 'metadata');