From e1b98d154e672aacf137798f906ec43d4861567f Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 3 Oct 2017 04:33:28 +1300 Subject: [PATCH] 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). --- src/Forms/HTMLEditor/TinyMCEConfig.php | 32 +++++++++++++++++-- src/Forms/HTMLEditor/TinyMCEGZIPGenerator.php | 5 +-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Forms/HTMLEditor/TinyMCEConfig.php b/src/Forms/HTMLEditor/TinyMCEConfig.php index bec47c21c..b94cd6fee 100644 --- a/src/Forms/HTMLEditor/TinyMCEConfig.php +++ b/src/Forms/HTMLEditor/TinyMCEConfig.php @@ -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('#(?[^/]+/[^/]+)\s*:\s*(?[^:]+)#', $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; diff --git a/src/Forms/HTMLEditor/TinyMCEGZIPGenerator.php b/src/Forms/HTMLEditor/TinyMCEGZIPGenerator.php index b575b5ae6..1da53bdd8 100644 --- a/src/Forms/HTMLEditor/TinyMCEGZIPGenerator.php +++ b/src/Forms/HTMLEditor/TinyMCEGZIPGenerator.php @@ -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!");