Add presave for development and public libraries
pull/50/head
Thomas Horn Sivertsen 2018-02-01 12:18:31 +01:00
parent 04edd73855
commit 615bac7c08
3 changed files with 19 additions and 11 deletions

View File

@ -457,13 +457,9 @@ class H5PDefaultStorage implements \H5PFileStorage {
* @param string $name
* @return bool
*/
public function hasPresave($name) {
$filePath = implode(DIRECTORY_SEPARATOR, [
$this->path,
'libraries',
$name,
'presave.js',
]);
public function hasPresave($libraryFolder, $developmentPath = null) {
$path = is_null($developmentPath) ? 'libraries' . DIRECTORY_SEPARATOR . $libraryFolder : $developmentPath;
$filePath = realpath($this->path . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . 'presave.js');
return file_exists($filePath);
}

View File

@ -194,7 +194,7 @@ interface H5PFileStorage {
/**
* Check if the library has a presave.js in the root folder
*
* @return string|null Path to script or null if missing
* @return string|null Path if presave.js found
*/
public function hasPresave($name);
public function hasPresave($libraryName, $developmentPath = null);
}

View File

@ -2118,7 +2118,7 @@ class H5PCore {
$dependency['version'] = "?ver={$dependency['majorVersion']}.{$dependency['minorVersion']}.{$dependency['patchVersion']}";
$this->getDependencyAssets($dependency, 'preloadedJs', $files['scripts'], $prefix);
$this->getDependencyAssets($dependency, 'preloadedCss', $files['styles'], $prefix);
if( $this->fs->hasPresave($libraryName) ){
if( $this->hasPresave($libraryName) ){
$this->addPresaveFile($files, $dependency, $prefix);
}
}
@ -2134,9 +2134,21 @@ class H5PCore {
return $files;
}
public function hasPresave($libraryName)
{
if( isset($this->h5pD) ){
extract(H5PCore::libraryFromString($libraryName));
$library = $this->h5pD->getLibrary($machineName, $majorVersion, $minorVersion);
if( !is_null($library)){
return $this->fs->hasPresave($libraryName, $library['path']);
}
}
return $this->fs->hasPresave($libraryName);
}
public function addPresaveFile(&$assets, $library, $prefix = ''){
$this->getDependencyAssets([
'path' => 'libraries' . DIRECTORY_SEPARATOR . self::libraryToString($library, true),
'path' => array_key_exists('path', $library) ? $library['path'] : 'libraries' . DIRECTORY_SEPARATOR . self::libraryToString($library, true),
'version' => array_key_exists('version', $library) ? $library['version'] : "?ver={$library['majorVersion']}.{$library['minorVersion']}.{$library['patchVersion']}",
'presaveJs' => ['presave.js']
], 'presaveJs', $assets['scripts'], $prefix);