Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
7 
12 
21 {
25  const WYSIWYG_ENABLED = 'enabled';
26 
30  const WYSIWYG_STATUS_CONFIG_PATH = 'cms/wysiwyg/enabled';
31 
35  const WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID = 'Magento_Cms::images/wysiwyg_skin_image.png';
36 
40  const WYSIWYG_HIDDEN = 'hidden';
41 
45  const WYSIWYG_DISABLED = 'disabled';
46 
50  const IMAGE_DIRECTORY = 'wysiwyg';
51 
55  protected $_authorization;
56 
60  protected $_assetRepo;
61 
67  protected $_variableConfig;
68 
74  protected $_widgetConfig;
75 
81  protected $_eventManager;
82 
88  protected $_scopeConfig;
89 
93  protected $_windowSize;
94 
98  protected $_backendUrl;
99 
103  protected $_storeManager;
104 
109  protected $filesystem;
110 
114  private $configProvider;
115 
132  public function __construct(
133  \Magento\Backend\Model\UrlInterface $backendUrl,
134  \Magento\Framework\Event\ManagerInterface $eventManager,
135  \Magento\Framework\AuthorizationInterface $authorization,
136  \Magento\Framework\View\Asset\Repository $assetRepo,
137  \Magento\Variable\Model\Variable\Config $variableConfig,
138  \Magento\Widget\Model\Widget\Config $widgetConfig,
139  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
142  array $windowSize = [],
143  array $data = [],
144  \Magento\Cms\Model\Wysiwyg\CompositeConfigProvider $configProvider = null
145  ) {
146  $this->_backendUrl = $backendUrl;
147  $this->_eventManager = $eventManager;
148  $this->_scopeConfig = $scopeConfig;
149  $this->_authorization = $authorization;
150  $this->_assetRepo = $assetRepo;
151  $this->_variableConfig = $variableConfig;
152  $this->_widgetConfig = $widgetConfig;
153  $this->_windowSize = $windowSize;
154  $this->_storeManager = $storeManager;
155  $this->filesystem = $filesystem;
156  $this->configProvider = $configProvider ?: ObjectManager::getInstance()
157  ->get(\Magento\Cms\Model\Wysiwyg\CompositeConfigProvider ::class);
158  parent::__construct($data);
159  }
160 
177  public function getConfig($data = [])
178  {
179  $config = new \Magento\Framework\DataObject();
180 
181  $config->setData(
182  [
183  'enabled' => $this->isEnabled(),
184  'hidden' => $this->isHidden(),
185  'baseStaticUrl' => $this->_assetRepo->getStaticViewFileContext()->getBaseUrl(),
186  'baseStaticDefaultUrl' => str_replace('index.php/', '', $this->_backendUrl->getBaseUrl())
187  . $this->filesystem->getUri(DirectoryList::STATIC_VIEW) . '/',
188  'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'),
189  'use_container' => false,
190  'add_variables' => true,
191  'add_widgets' => true,
192  'no_display' => false,
193  'add_directives' => true,
194  'width' => '100%',
195  'height' => '500px',
196  'plugins' => [],
197  ]
198  );
199 
200  $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url')));
201 
202  if (is_array($data)) {
203  $config->addData($data);
204  }
205 
206  if ($this->_authorization->isAllowed('Magento_Cms::media_gallery')) {
207  $this->configProvider->processGalleryConfig($config);
208  $config->addData(
209  [
210  'files_browser_window_width' => $this->_windowSize['width'],
211  'files_browser_window_height' => $this->_windowSize['height'],
212  ]
213  );
214  }
215  if ($config->getData('add_widgets')) {
216  $this->configProvider->processWidgetConfig($config);
217  }
218 
219  if ($config->getData('add_variables')) {
220  $this->configProvider->processVariableConfig($config);
221  }
222 
223  return $this->configProvider->processWysiwygConfig($config);
224  }
225 
231  public function getSkinImagePlaceholderPath()
232  {
233  $staticPath = $this->_storeManager->getStore()->getBaseStaticDir();
234  $placeholderPath = $this->_assetRepo->createAsset(self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID)->getPath();
235  return $staticPath . '/' . $placeholderPath;
236  }
237 
243  public function isEnabled()
244  {
245  $wysiwygState = $this->_scopeConfig->getValue(
246  self::WYSIWYG_STATUS_CONFIG_PATH,
248  $this->getStoreId()
249  );
250  return in_array($wysiwygState, [self::WYSIWYG_ENABLED, self::WYSIWYG_HIDDEN]);
251  }
252 
258  public function isHidden()
259  {
260  $status = $this->_scopeConfig->getValue(
261  self::WYSIWYG_STATUS_CONFIG_PATH,
263  );
264  return $status == self::WYSIWYG_HIDDEN;
265  }
266 }
$config
Definition: fraud_order.php:17
$storeManager
__construct(\Magento\Backend\Model\UrlInterface $backendUrl, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\AuthorizationInterface $authorization, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Variable\Model\Variable\Config $variableConfig, \Magento\Widget\Model\Widget\Config $widgetConfig, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, Filesystem $filesystem, array $windowSize=[], array $data=[], \Magento\Cms\Model\Wysiwyg\CompositeConfigProvider $configProvider=null)
Definition: Config.php:132
$status
Definition: order_status.php:8