function opigno_module_page_top in Opigno module 3.x
Same name and namespace in other branches
- 8 opigno_module.module \opigno_module_page_top()
Implements hook_page_top().
File
- ./
opigno_module.module, line 868 - Contains opigno_module.module.
Code
function opigno_module_page_top(array &$page_top) {
// Install h5p libraries.
$interface = H5PDrupal::getInstance();
if (empty($interface
->loadLibraries())) {
$h5p_default_path = $interface
->getOption('default_path', 'h5p');
$temporary_file_path = 'public://' . $h5p_default_path . '/temp/' . uniqid('h5p-');
\Drupal::service('file_system')
->prepareDirectory($temporary_file_path, FileSystemInterface::MODIFY_PERMISSIONS | FileSystemInterface::CREATE_DIRECTORY);
// Load libraries.h5p.
$file_content = file_get_contents(drupal_get_path("profile", "opigno_lms") . "/h5plib/libraries.h5p");
$file = file_save_data($file_content, $temporary_file_path . '.h5p', FileSystemInterface::EXISTS_REPLACE);
if ($file) {
$uri = $file
->getFileUri();
$interface
->getUploadedH5pPath(\Drupal::service('file_system')
->realpath($uri));
$interface
->getUploadedH5pFolderPath(\Drupal::service('file_system')
->realpath($temporary_file_path));
// Validate libraries.
$upgradeOnly = FALSE;
$validator = H5PDrupal::getInstance('validator');
$validator
->isValidPackage(TRUE, $upgradeOnly);
// Save libraries.
$storage = H5PDrupal::getInstance('storage');
$storage
->savePackage(NULL, NULL, TRUE);
}
}
}