assetHandler = $assetHandler;
return $this;
}
/**
* Get backend for assets
* @return GeneratedAssetHandler
*/
public function getAssetHandler()
{
return $this->assetHandler;
}
/**
* Generate a script URL for the given config
*
* @param TinyMCEConfig $config
* @return string
*/
public function getScriptURL(TinyMCEConfig $config)
{
// Build URL for this config based on named config and hash of settings
$url = $this->generateFilename($config);
// Pass content generator
return $this->getAssetHandler()->getContentURL($url, function () use ($config) {
return $this->generateContent($config);
});
}
/**
* Build raw config for tinymce
*
* @param TinyMCEConfig $config
* @return string
*/
public function generateContent(TinyMCEConfig $config)
{
$tinymceDir = $config->getTinyMCEPath();
$files = [ ];
// Add core languages
$language = $config->getOption('language');
if ($language) {
$files[] = $tinymceDir . '/langs/' . $language;
}
// Add plugins, along with any plugin specific lang files
foreach ($config->getPlugins() as $plugin => $path) {
// Add external plugin
if ($path) {
if ($path instanceof ModuleResource) {
// Resolve path / url later
$files[] = $path;
} elseif (Director::is_absolute_url($path) || strpos($path, '/') === 0) {
// Convert URLS to relative paths
$path = Director::makeRelative($path);
if ($path) {
$files[] = $path;
}
} else {
// Relative URLs are safe
$files[] = $path;
}
continue;
}
// Core tinymce plugin
$files[] = $tinymceDir . '/plugins/' . $plugin . '/plugin';
if ($language) {
$files[] = $tinymceDir . '/plugins/' . $plugin . '/langs/' . $language;
}
}
// Add themes
$theme = $config->getTheme();
if ($theme) {
$files[] = $tinymceDir . '/themes/' . $theme . '/theme';
if ($language) {
$files[] = $tinymceDir . '/themes/' . $theme . '/langs/' . $language;
}
}
// Process source files
$files = array_filter(array_map(function ($file) {
if ($file instanceof ModuleResource) {
return $file;
}
// Prioritise preferred paths
$paths = [
$file,
$file . '.min.js',
$file . '.js',
];
foreach ($paths as $path) {
if (file_exists(Director::baseFolder() . '/' . $path)) {
return $path;
}
}
return null;
}, $files));
$libContent = $this->getFileContents(Director::baseFolder() . '/' . $tinymceDir . '/tinymce.min.js');
// Register vars for config
$baseDirJS = Convert::raw2js(Director::absoluteBaseURL());
$buffer = [];
$buffer[] = <<