mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
8e49b563a9
commit
e1b98d154e
@ -567,7 +567,7 @@ class TinyMCEConfig extends HTMLEditorConfig
|
|||||||
$settings['document_base_url'] = Director::absoluteBaseURL();
|
$settings['document_base_url'] = Director::absoluteBaseURL();
|
||||||
|
|
||||||
// https://www.tinymce.com/docs/api/class/tinymce.editormanager/#baseURL
|
// 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;
|
$settings['baseURL'] = $tinyMCEBaseURL;
|
||||||
|
|
||||||
// map all plugins to absolute urls for loading
|
// map all plugins to absolute urls for loading
|
||||||
@ -681,6 +681,26 @@ class TinyMCEConfig extends HTMLEditorConfig
|
|||||||
return 'en';
|
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
|
* @return string
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@ -712,14 +732,20 @@ class TinyMCEConfig extends HTMLEditorConfig
|
|||||||
* Expand resource path to a relative filesystem path
|
* Expand resource path to a relative filesystem path
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
|
* @param boolean $useResourcePath The resource path can be different than the original tinymce location.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function resolvePath($path)
|
protected function resolvePath($path, $useResourcePath = false)
|
||||||
{
|
{
|
||||||
if (preg_match('#(?<module>[^/]+/[^/]+)\s*:\s*(?<path>[^:]+)#', $path, $results)) {
|
if (preg_match('#(?<module>[^/]+/[^/]+)\s*:\s*(?<path>[^:]+)#', $path, $results)) {
|
||||||
$module = ModuleLoader::getModule($results['module']);
|
$module = ModuleLoader::getModule($results['module']);
|
||||||
if ($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;
|
return $path;
|
||||||
|
@ -33,10 +33,11 @@ class TinyMCEGZIPGenerator implements TinyMCEScriptGenerator
|
|||||||
// If gzip is disabled just return core script url
|
// If gzip is disabled just return core script url
|
||||||
$useGzip = HTMLEditorField::config()->get('use_gzip');
|
$useGzip = HTMLEditorField::config()->get('use_gzip');
|
||||||
if (!$useGzip) {
|
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';
|
$gzipPath = BASE_PATH . '/' . $config->getTinyMCEPath() . '/tiny_mce_gzip.php';
|
||||||
if (!file_exists($gzipPath)) {
|
if (!file_exists($gzipPath)) {
|
||||||
throw new Exception("HTMLEditorField.use_gzip enabled, but file $gzipPath does not exist!");
|
throw new Exception("HTMLEditorField.use_gzip enabled, but file $gzipPath does not exist!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user