From c589285351d5471be05484e35d73917eb61579d5 Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Mon, 26 Mar 2018 11:24:26 +0200 Subject: [PATCH] HFP-1905 Fix unset values for array fields Some array fields were filled with undefined and lead to warnings. --- h5p.classes.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 3f54f0d..659475c 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1600,18 +1600,15 @@ Class H5PExport { 'title' => $content['title'], 'language' => (isset($content['language']) && strlen(trim($content['language'])) !== 0) ? $content['language'] : 'und', 'mainLibrary' => $content['library']['name'], - 'embedTypes' => $embedTypes, - 'authors' => json_decode(json_encode($content['metadata']['authors'], TRUE)), - 'source' => $content['metadata']['source'], - 'yearFrom' => $content['metadata']['yearFrom'], - 'yearTo' => $content['metadata']['yearTo'], - 'license' => $content['metadata']['license'], - 'licenseVersion' => $content['metadata']['licenseVersion'], - 'licenseExtras' => $content['metadata']['licenseExtras'], - 'changes' => json_decode(json_encode($content['metadata']['changes'], TRUE)), - 'authorComments' => $content['metadata']['authorComments'] + 'embedTypes' => $embedTypes ); + foreach(array('authors', 'source', 'license', 'licenseVersion', 'licenseExtras' ,'yearFrom', 'yearTo', 'changes', 'authorComments') as $field) { + if (isset($content['metadata'][$field])) { + $h5pJson[$field] = json_decode(json_encode($content['metadata'][$field], TRUE)); + } + } + // Remove all values that are not set foreach ($h5pJson as $key => $value) { if (!isset($value)) {