Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H5P Content Type "Interactive Book" not working #31

Open
r-kraemer opened this issue Apr 7, 2022 · 4 comments
Open

H5P Content Type "Interactive Book" not working #31

r-kraemer opened this issue Apr 7, 2022 · 4 comments

Comments

@r-kraemer
Copy link

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
Copy link

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
Copy link
Author

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

@ulrike-cosmoblonde
Copy link

Here you go ;-) cb_h5p.zip

@r-kraemer
Copy link
Author

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants