Fix tinymce operation for resource paths

It was referencing secondary TinyMCE assets in the vendor/* folder
from its generated files (e.g. skin.min.css).
This commit is contained in:
Ingo Schommer 2017-10-03 04:33:28 +13:00
parent 8e49b563a9
commit e1b98d154e
2 changed files with 32 additions and 5 deletions

View File

@ -567,7 +567,7 @@ class TinyMCEConfig extends HTMLEditorConfig
$settings['document_base_url'] = Director::absoluteBaseURL();
// https://www.tinymce.com/docs/api/class/tinymce.editormanager/#baseURL
$tinyMCEBaseURL = Controller::join_links(Director::baseURL(), $this->getTinyMCEPath());
$tinyMCEBaseURL = Controller::join_links(Director::baseURL(), $this->getTinyMCEResourcePath());
$settings['baseURL'] = $tinyMCEBaseURL;
// map all plugins to absolute urls for loading
@ -681,6 +681,26 @@ class TinyMCEConfig extends HTMLEditorConfig
return 'en';
}
/**
* Returns the base path to TinyMCE resources (which could be different from the original tinymce
* location in the module).
*
* @return string
* @throws Exception
*/
public function getTinyMCEResourcePath()
{
$configDir = static::config()->get('base_dir');
if ($configDir) {
return $this->resolvePath($configDir, true);
}
throw new Exception(sprintf(
'If the silverstripe/admin module is not installed you must set the TinyMCE path in %s.base_dir',
__CLASS__
));
}
/**
* @return string
* @throws Exception
@ -712,14 +732,20 @@ class TinyMCEConfig extends HTMLEditorConfig
* Expand resource path to a relative filesystem path
*
* @param string $path
* @param boolean $useResourcePath The resource path can be different than the original tinymce location.
* @return string
*/
protected function resolvePath($path)
protected function resolvePath($path, $useResourcePath = false)
{
if (preg_match('#(?<module>[^/]+/[^/]+)\s*:\s*(?<path>[^:]+)#', $path, $results)) {
$module = ModuleLoader::getModule($results['module']);
if ($module) {
return $module->getRelativeResourcePath($results['path']);
if ($useResourcePath) {
return $module->getResource($results['path'])->getURL();
} else {
return $module->getResource($results['path'])->getRelativePath();
}
}
}
return $path;

View File

@ -33,10 +33,11 @@ class TinyMCEGZIPGenerator implements TinyMCEScriptGenerator
// If gzip is disabled just return core script url
$useGzip = HTMLEditorField::config()->get('use_gzip');
if (!$useGzip) {
return $config->getTinyMCEPath() . '/tinymce.min.js';
return $config->getTinyMCEResourcePath() . '/tinymce.min.js';
}
// tinyMCE JS requirement
// tinyMCE JS requirement - use the original module path,
// don't assume the PHP file is copied alongside the resources
$gzipPath = BASE_PATH . '/' . $config->getTinyMCEPath() . '/tiny_mce_gzip.php';
if (!file_exists($gzipPath)) {
throw new Exception("HTMLEditorField.use_gzip enabled, but file $gzipPath does not exist!");