16
16
use Magento \Cms \Model \Wysiwyg \CompositeConfigProvider ;
17
17
use Magento \Framework \App \Config \ScopeConfigInterface ;
18
18
use Magento \Framework \Data \Wysiwyg \ConfigProviderInterface ;
19
+ use Magento \Framework \Exception \ConfigurationMismatchException ;
20
+ use Psr \Log \LoggerInterface ;
19
21
20
22
class WysiwygConfigProviderPlugin
21
23
{
@@ -31,15 +33,21 @@ class WysiwygConfigProviderPlugin
31
33
* @var CompositeConfigProvider
32
34
*/
33
35
private $ compositeConfigProvider ;
36
+ /**
37
+ * @var LoggerInterface
38
+ */
39
+ private $ logger ;
34
40
35
41
public function __construct (
36
42
array $ additionalSettings ,
37
43
ScopeConfigInterface $ scopeConfig ,
38
- CompositeConfigProvider $ compositeConfigProvider
44
+ CompositeConfigProvider $ compositeConfigProvider ,
45
+ LoggerInterface $ logger
39
46
) {
40
47
$ this ->additionalSettings = $ additionalSettings ;
41
48
$ this ->scopeConfig = $ scopeConfig ;
42
49
$ this ->compositeConfigProvider = $ compositeConfigProvider ;
50
+ $ this ->logger = $ logger ;
43
51
}
44
52
45
53
public function afterGetConfig (
@@ -48,16 +56,21 @@ public function afterGetConfig(
48
56
) {
49
57
$ toolbar = implode (' ' , explode (', ' , $ this ->scopeConfig ->getValue ('cms/wysiwyg/toolbar ' )));
50
58
59
+ try {
60
+ $ tinyMceVersionIdentifier = $ this ->getTinyMceVersionIdentifier ($ result );
61
+ } catch (ConfigurationMismatchException $ e ) {
62
+ $ this ->logger ->error ($ e ->getMessage ());
63
+ return $ result ;
64
+ }
51
65
$ result ->setData (
52
- ' tinymce4 ' ,
66
+ $ tinyMceVersionIdentifier ,
53
67
[
54
68
'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 ' ],
57
71
]
58
72
);
59
73
60
- //$result->setData('settings', $this->additionalSettings);
61
74
$ result ->setData ('add_variables ' , $ this ->scopeConfig ->isSetFlag ('cms/wysiwyg/add_variable ' ));
62
75
$ result ->setData ('add_widgets ' , $ this ->scopeConfig ->isSetFlag ('cms/wysiwyg/add_widget ' ));
63
76
$ result ->setData ('add_images ' , $ this ->scopeConfig ->isSetFlag ('cms/wysiwyg/add_image ' ));
@@ -82,4 +95,20 @@ public function afterGetConfig(
82
95
83
96
return $ result ;
84
97
}
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
+ }
85
114
}
0 commit comments