1616use Magento \Cms \Model \Wysiwyg \CompositeConfigProvider ;
1717use Magento \Framework \App \Config \ScopeConfigInterface ;
1818use Magento \Framework \Data \Wysiwyg \ConfigProviderInterface ;
19+ use Magento \Framework \Exception \ConfigurationMismatchException ;
20+ use Psr \Log \LoggerInterface ;
1921
2022class WysiwygConfigProviderPlugin
2123{
@@ -31,15 +33,21 @@ class WysiwygConfigProviderPlugin
3133 * @var CompositeConfigProvider
3234 */
3335 private $ compositeConfigProvider ;
36+ /**
37+ * @var LoggerInterface
38+ */
39+ private $ logger ;
3440
3541 public function __construct (
3642 array $ additionalSettings ,
3743 ScopeConfigInterface $ scopeConfig ,
38- CompositeConfigProvider $ compositeConfigProvider
44+ CompositeConfigProvider $ compositeConfigProvider ,
45+ LoggerInterface $ logger
3946 ) {
4047 $ this ->additionalSettings = $ additionalSettings ;
4148 $ this ->scopeConfig = $ scopeConfig ;
4249 $ this ->compositeConfigProvider = $ compositeConfigProvider ;
50+ $ this ->logger = $ logger ;
4351 }
4452
4553 public function afterGetConfig (
@@ -48,16 +56,21 @@ public function afterGetConfig(
4856 ) {
4957 $ toolbar = implode (' ' , explode (', ' , $ this ->scopeConfig ->getValue ('cms/wysiwyg/toolbar ' )));
5058
59+ try {
60+ $ tinyMceVersionIdentifier = $ this ->getTinyMceVersionIdentifier ($ result );
61+ } catch (ConfigurationMismatchException $ e ) {
62+ $ this ->logger ->error ($ e ->getMessage ());
63+ return $ result ;
64+ }
5165 $ result ->setData (
52- ' tinymce4 ' ,
66+ $ tinyMceVersionIdentifier ,
5367 [
5468 'toolbar ' => $ toolbar ,
55- 'plugins ' => $ result ->getData (' tinymce4 ' )['plugins ' ],
56- 'content_css ' => $ result ->getData (' tinymce4 ' )['content_css ' ],
69+ 'plugins ' => $ result ->getData ($ tinyMceVersionIdentifier )['plugins ' ],
70+ 'content_css ' => $ result ->getData ($ tinyMceVersionIdentifier )['content_css ' ],
5771 ]
5872 );
5973
60- //$result->setData('settings', $this->additionalSettings);
6174 $ result ->setData ('add_variables ' , $ this ->scopeConfig ->isSetFlag ('cms/wysiwyg/add_variable ' ));
6275 $ result ->setData ('add_widgets ' , $ this ->scopeConfig ->isSetFlag ('cms/wysiwyg/add_widget ' ));
6376 $ result ->setData ('add_images ' , $ this ->scopeConfig ->isSetFlag ('cms/wysiwyg/add_image ' ));
@@ -82,4 +95,20 @@ public function afterGetConfig(
8295
8396 return $ result ;
8497 }
98+
99+ /**
100+ * @throws ConfigurationMismatchException
101+ */
102+ private function getTinyMceVersionIdentifier (\Magento \Framework \DataObject $ result ): string
103+ {
104+ if (!empty ($ result ->getData ('tinymce ' ))) {
105+ return 'tinymce ' ;
106+ }
107+ if (!empty ($ result ->getData ('tinymce4 ' ))) {
108+ return 'tinymce4 ' ;
109+ }
110+ throw new ConfigurationMismatchException (
111+ __ ('No supported version of TinyMCE found. ' )
112+ );
113+ }
85114}
0 commit comments