Tuurlijk / t3ext-h5p

TYPO3 H5P plugin
7 stars 16 forks source link

H5P Content Type "Interactive Book" not working #31

Open r-kraemer opened 2 years ago

r-kraemer commented 2 years ago

Hi, the Content Type "Interactive Book" is quite useful and versatile. However it will not display/render properly, pls. refer to the screenshot of the console output.

Typo3 Version 11.5.8, H5P Version 11.5.10

Bildschirmfoto 2022-04-07 um 11 50 39
ulrike-cosmoblonde commented 2 years ago

Hi, as we had the urgent need to solve this issue, we created an extension that extends the class site/typo3conf/ext/cb_h5p/Classes/Controller/ViewController.php from the h5p extension as a temporary fix. Not only the error "only one instance of babel-polyfill is allowed" happens, but also a 2nd error "Uncaught TypeError: i.metadata is undefined" appears. Only this 2nd error prevents interactiveBooks from showing in the frontend!

We only overwrote and adjusted the indexAction in our extension with the following lines:

     // Fix for error: "i.metadata is undefined"
     // add missing metadata from DB field parameters:
        if(!key_exists('metadata',$contentSettings)){
            $h5pParameters = json_decode($content->getParameters());
            if($h5pParameters->metadata){
                $contentSettings['metadata'] = $h5pParameters->metadata;
            }else{
                // if no metadata is available in DB data, initialise with empty array
                $contentSettings['metadata'] = array();
            }
        }

        // Fix for error: "Only one instance of babel-polyfill is allowed" => remove h5p-interactive-book.js duplicate from scripts array
        // $contentSettings['scripts'] array contains twice: "/fileadmin/h5p/libraries/H5P.InteractiveBook-1.5/dist/h5p-interactive-book.js?v=0.3.0"
        //check if h5p-interactive-book.js is in the array more then once => if yes, remove duplicate

        $found = false;
        foreach($contentSettings['scripts'] as $key => $value){
            if(strpos($value,'h5p-interactive-book.js') > 0){
                if($found == false){
                    $found = true;
                }else{
                    unset($contentSettings['scripts'][$key]);
                    break;
                }
            }
        }

Note: a more generic approach to remove script duplicates like array_unique($contentSettings['scripts']); did not work!

Maybe this fix can be added to the original extension or rather used as a basis for a more elegant solution ;-)

Regards! Ulrike

r-kraemer commented 2 years ago

Hello Ulrike, kindly share the customised ViewController.php, thank you

ulrike-cosmoblonde commented 2 years ago

Here you go ;-) cb_h5p.zip

r-kraemer commented 2 years ago

thank you!