JI-857 Validate metadata

HFP-2095-Fix-table-styling
Paal Joergensen 2018-09-17 08:58:38 +02:00
parent 74f9a84034
commit 4fe8eca0f2
1 changed files with 26 additions and 0 deletions

View File

@ -1939,6 +1939,10 @@ class H5PCore {
$content = $this->h5pF->loadContent($id);
if ($content !== NULL) {
// Validate main content's metadata
$validator = new H5PContentValidator($this->h5pF, $this);
$validator->validateMetadata($content['metadata']);
$content['library'] = array(
'id' => $content['libraryId'],
'name' => $content['libraryName'],
@ -3367,6 +3371,21 @@ class H5PContentValidator {
return $this->dependencies;
}
/**
* Validate metadata
*
* @param array $metadata
*/
public function validateMetadata(&$metadata) {
$semantics = $this->getMetadataSemantics();
$group = (object)$metadata;
$this->validateGroup($group, (object) array(
'type' => 'group',
'fields' => $semantics,
), FALSE);
}
/**
* Validate given text value against text semantics.
* @param $text
@ -3883,10 +3902,17 @@ class H5PContentValidator {
$library = $this->libraries[$value->library];
}
// Validate parameters
$this->validateGroup($value->params, (object) array(
'type' => 'group',
'fields' => $library['semantics'],
), FALSE);
// Validate subcontent's metadata
if (isset($value->metadata)) {
$this->validateMetadata($value->metadata);
}
$validKeys = array('library', 'params', 'subContentId', 'metadata');
if (isset($semantics->extraAttributes)) {
$validKeys = array_merge($validKeys, $semantics->extraAttributes);