_backendUrl = $backendUrl; $this->_eventManager = $eventManager; $this->_scopeConfig = $scopeConfig; $this->_authorization = $authorization; $this->_assetRepo = $assetRepo; $this->_variableConfig = $variableConfig; $this->_widgetConfig = $widgetConfig; $this->_windowSize = $windowSize; $this->_storeManager = $storeManager; $this->filesystem = $filesystem; $this->configProvider = $configProvider ?: ObjectManager::getInstance() ->get(\Magento\Cms\Model\Wysiwyg\CompositeConfigProvider ::class); parent::__construct($data); } /** * Return Wysiwyg config as \Magento\Framework\DataObject * * Config options description: * * enabled: Enabled Visual Editor or not * hidden: Show Visual Editor on page load or not * use_container: Wrap Editor contents into div or not * no_display: Hide Editor container or not (related to use_container) * translator: Helper to translate phrases in lib * files_browser_*: Files Browser (media, images) settings * encode_directives: Encode template directives with JS or not * * @param array|\Magento\Framework\DataObject $data Object constructor params to override default config values * @return \Magento\Framework\DataObject */ public function getConfig($data = []) { $config = new \Magento\Framework\DataObject(); $config->setData( [ 'enabled' => $this->isEnabled(), 'hidden' => $this->isHidden(), 'baseStaticUrl' => $this->_assetRepo->getStaticViewFileContext()->getBaseUrl(), 'baseStaticDefaultUrl' => str_replace('index.php/', '', $this->_backendUrl->getBaseUrl()) . $this->filesystem->getUri(DirectoryList::STATIC_VIEW) . '/', 'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'), 'use_container' => false, 'add_variables' => true, 'add_widgets' => true, 'no_display' => false, 'add_directives' => true, 'width' => '100%', 'height' => '500px', 'plugins' => [], ] ); $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url'))); if (is_array($data)) { $config->addData($data); } if ($this->_authorization->isAllowed('Magento_Cms::media_gallery')) { $this->configProvider->processGalleryConfig($config); $config->addData( [ 'files_browser_window_width' => $this->_windowSize['width'], 'files_browser_window_height' => $this->_windowSize['height'], ] ); } if ($config->getData('add_widgets')) { $this->configProvider->processWidgetConfig($config); } if ($config->getData('add_variables')) { $this->configProvider->processVariableConfig($config); } return $this->configProvider->processWysiwygConfig($config); } /** * Return path for skin images placeholder * * @return string */ public function getSkinImagePlaceholderPath() { $staticPath = $this->_storeManager->getStore()->getBaseStaticDir(); $placeholderPath = $this->_assetRepo->createAsset(self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID)->getPath(); return $staticPath . '/' . $placeholderPath; } /** * Check whether Wysiwyg is enabled or not * * @return bool */ public function isEnabled() { $wysiwygState = $this->_scopeConfig->getValue( self::WYSIWYG_STATUS_CONFIG_PATH, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->getStoreId() ); return in_array($wysiwygState, [self::WYSIWYG_ENABLED, self::WYSIWYG_HIDDEN]); } /** * Check whether Wysiwyg is loaded on demand or not * * @return bool */ public function isHidden() { $status = $this->_scopeConfig->getValue( self::WYSIWYG_STATUS_CONFIG_PATH, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); return $status == self::WYSIWYG_HIDDEN; } }