1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Model\Wysiwyg;
/**
* Class CompositeConfigProvider loads required config by adapter specified in system configuration
* General > Content Management >WYSIWYG Options > WYSIWYG Editor
*/
class CompositeConfigProvider
{
/**
* @var \Magento\Ui\Block\Wysiwyg\ActiveEditor
*/
private $activeEditor;
/**
* List of variable config processors by adapter type
*
* @var array
*/
private $variablePluginConfigProvider;
/**
* List of widget config processors by adapter type
*
* @var array
*/
private $widgetPluginConfigProvider;
/**
* List of wysiwyg config postprocessors by adapter type
*
* @var array
*/
private $wysiwygConfigPostProcessor;
/**
* Factory to create required processor object
*
* @var \Magento\Cms\Model\Wysiwyg\ConfigProviderFactory
*/
private $configProviderFactory;
/**
* Current active editor path
*
* @var string
*/
private $activeEditorPath;
/**
* List of gallery config processors by adapter type
*
* @var array
*/
private $galleryConfigProvider;
/**
* @param \Magento\Ui\Block\Wysiwyg\ActiveEditor $activeEditor
* @param ConfigProviderFactory $configProviderFactory
* @param array $variablePluginConfigProvider
* @param array $widgetPluginConfigProvider
* @param array $galleryConfigProvider
* @param array $wysiwygConfigPostProcessor
*/
public function __construct(
\Magento\Ui\Block\Wysiwyg\ActiveEditor $activeEditor,
\Magento\Cms\Model\Wysiwyg\ConfigProviderFactory $configProviderFactory,
array $variablePluginConfigProvider,
array $widgetPluginConfigProvider,
array $galleryConfigProvider,
array $wysiwygConfigPostProcessor
) {
$this->activeEditor = $activeEditor;
$this->configProviderFactory = $configProviderFactory;
$this->variablePluginConfigProvider = $variablePluginConfigProvider;
$this->widgetPluginConfigProvider = $widgetPluginConfigProvider;
$this->galleryConfigProvider = $galleryConfigProvider;
$this->wysiwygConfigPostProcessor = $wysiwygConfigPostProcessor;
}
/**
* Add config for variable plugin
*
* @param \Magento\Framework\DataObject $config
* @return \Magento\Framework\DataObject
*/
public function processVariableConfig($config)
{
return $this->updateConfig($config, $this->variablePluginConfigProvider);
}
/**
* Add config for widget plugin
*
* @param \Magento\Framework\DataObject $config
* @return \Magento\Framework\DataObject
*/
public function processWidgetConfig($config)
{
return $this->updateConfig($config, $this->widgetPluginConfigProvider);
}
/**
* Add config for gallery
*
* @param \Magento\Framework\DataObject $config
* @return \Magento\Framework\DataObject
*/
public function processGalleryConfig($config)
{
return $this->updateConfig($config, $this->galleryConfigProvider);
}
/**
* Update wysiwyg config with data required for adapter
*
* @param \Magento\Framework\DataObject $config
* @return \Magento\Framework\DataObject
*/
public function processWysiwygConfig($config)
{
return $this->updateConfig($config, $this->wysiwygConfigPostProcessor);
}
/**
* Returns active editor path
*
* @param \Magento\Framework\DataObject $config
* @return string
*/
private function getActiveEditorPath($config)
{
if (!isset($this->activeEditorPath) || $this->activeEditorPath !== $config->getData('activeEditorPath')) {
$this->activeEditorPath = $config->getData('activeEditorPath')
? $config->getData('activeEditorPath')
: $this->activeEditor->getWysiwygAdapterPath();
$config->setData('activeEditorPath', $this->activeEditorPath);
}
return $this->activeEditorPath;
}
/**
* Update config using config provider by active editor path
*
* @param \Magento\Framework\DataObject $config
* @param array $configProviders
* @return \Magento\Framework\DataObject
*/
private function updateConfig($config, array $configProviders)
{
$adapterType = $this->getActiveEditorPath($config);
//Extension point to update plugin settings by adapter type
$providerClass = isset($configProviders[$adapterType])
? $configProviders[$adapterType]
: $configProviders['default'];
/** @var \Magento\Framework\Data\Wysiwyg\ConfigProviderInterface $provider */
$provider = $this->configProviderFactory->create($providerClass);
return $provider->getConfig($config);
}
}