PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/magento/module-cms/Model/Wysiwyg/Config.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 240 lines | 113 code | 27 blank | 100 comment | 5 complexity | b2b74fe5cede0d8314ad4e03a13908e8 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Cms\Model\Wysiwyg;
  7. /**
  8. * Wysiwyg Config for Editor HTML Element
  9. */
  10. class Config extends \Magento\Framework\DataObject
  11. {
  12. /**
  13. * Wysiwyg status enabled
  14. */
  15. const WYSIWYG_ENABLED = 'enabled';
  16. /**
  17. * Wysiwyg status configuration path
  18. */
  19. const WYSIWYG_STATUS_CONFIG_PATH = 'cms/wysiwyg/enabled';
  20. /**
  21. *
  22. */
  23. const WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID = 'Magento_Cms::images/wysiwyg_skin_image.png';
  24. /**
  25. * Wysiwyg status hidden
  26. */
  27. const WYSIWYG_HIDDEN = 'hidden';
  28. /**
  29. * Wysiwyg status disabled
  30. */
  31. const WYSIWYG_DISABLED = 'disabled';
  32. /**
  33. * Wysiwyg image directory
  34. */
  35. const IMAGE_DIRECTORY = 'wysiwyg';
  36. /**
  37. * @var \Magento\Framework\AuthorizationInterface
  38. */
  39. protected $_authorization;
  40. /**
  41. * @var \Magento\Framework\View\Asset\Repository
  42. */
  43. protected $_assetRepo;
  44. /**
  45. * @var \Magento\Variable\Model\Variable\Config
  46. */
  47. protected $_variableConfig;
  48. /**
  49. * @var \Magento\Widget\Model\Widget\Config
  50. */
  51. protected $_widgetConfig;
  52. /**
  53. * Core event manager proxy
  54. *
  55. * @var \Magento\Framework\Event\ManagerInterface
  56. */
  57. protected $_eventManager;
  58. /**
  59. * Core store config
  60. *
  61. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  62. */
  63. protected $_scopeConfig;
  64. /**
  65. * @var array
  66. */
  67. protected $_windowSize;
  68. /**
  69. * @var \Magento\Backend\Model\UrlInterface
  70. */
  71. protected $_backendUrl;
  72. /**
  73. * @var \Magento\Store\Model\StoreManagerInterface
  74. */
  75. protected $_storeManager;
  76. /**
  77. * @param \Magento\Backend\Model\UrlInterface $backendUrl
  78. * @param \Magento\Framework\Event\ManagerInterface $eventManager
  79. * @param \Magento\Framework\AuthorizationInterface $authorization
  80. * @param \Magento\Framework\View\Asset\Repository $assetRepo
  81. * @param \Magento\Variable\Model\Variable\Config $variableConfig
  82. * @param \Magento\Widget\Model\Widget\Config $widgetConfig
  83. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  84. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  85. * @param array $windowSize
  86. * @param array $data
  87. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  88. */
  89. public function __construct(
  90. \Magento\Backend\Model\UrlInterface $backendUrl,
  91. \Magento\Framework\Event\ManagerInterface $eventManager,
  92. \Magento\Framework\AuthorizationInterface $authorization,
  93. \Magento\Framework\View\Asset\Repository $assetRepo,
  94. \Magento\Variable\Model\Variable\Config $variableConfig,
  95. \Magento\Widget\Model\Widget\Config $widgetConfig,
  96. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  97. \Magento\Store\Model\StoreManagerInterface $storeManager,
  98. array $windowSize = [],
  99. array $data = []
  100. ) {
  101. $this->_backendUrl = $backendUrl;
  102. $this->_eventManager = $eventManager;
  103. $this->_scopeConfig = $scopeConfig;
  104. $this->_authorization = $authorization;
  105. $this->_assetRepo = $assetRepo;
  106. $this->_variableConfig = $variableConfig;
  107. $this->_widgetConfig = $widgetConfig;
  108. $this->_windowSize = $windowSize;
  109. $this->_storeManager = $storeManager;
  110. parent::__construct($data);
  111. }
  112. /**
  113. * Return Wysiwyg config as \Magento\Framework\DataObject
  114. *
  115. * Config options description:
  116. *
  117. * enabled: Enabled Visual Editor or not
  118. * hidden: Show Visual Editor on page load or not
  119. * use_container: Wrap Editor contents into div or not
  120. * no_display: Hide Editor container or not (related to use_container)
  121. * translator: Helper to translate phrases in lib
  122. * files_browser_*: Files Browser (media, images) settings
  123. * encode_directives: Encode template directives with JS or not
  124. *
  125. * @param array|\Magento\Framework\DataObject $data Object constructor params to override default config values
  126. * @return \Magento\Framework\DataObject
  127. */
  128. public function getConfig($data = [])
  129. {
  130. $config = new \Magento\Framework\DataObject();
  131. $config->setData(
  132. [
  133. 'enabled' => $this->isEnabled(),
  134. 'hidden' => $this->isHidden(),
  135. 'use_container' => false,
  136. 'add_variables' => true,
  137. 'add_widgets' => true,
  138. 'no_display' => false,
  139. 'encode_directives' => true,
  140. 'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'),
  141. 'popup_css' => $this->_assetRepo->getUrl(
  142. 'mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'
  143. ),
  144. 'content_css' => $this->_assetRepo->getUrl(
  145. 'mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css'
  146. ),
  147. 'width' => '100%',
  148. 'plugins' => [],
  149. ]
  150. );
  151. $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url')));
  152. if ($this->_authorization->isAllowed('Magento_Cms::media_gallery')) {
  153. $config->addData(
  154. [
  155. 'add_images' => true,
  156. 'files_browser_window_url' => $this->_backendUrl->getUrl('cms/wysiwyg_images/index'),
  157. 'files_browser_window_width' => $this->_windowSize['width'],
  158. 'files_browser_window_height' => $this->_windowSize['height'],
  159. ]
  160. );
  161. }
  162. if (is_array($data)) {
  163. $config->addData($data);
  164. }
  165. if ($config->getData('add_variables')) {
  166. $settings = $this->_variableConfig->getWysiwygPluginSettings($config);
  167. $config->addData($settings);
  168. }
  169. if ($config->getData('add_widgets')) {
  170. $settings = $this->_widgetConfig->getPluginSettings($config);
  171. $config->addData($settings);
  172. }
  173. return $config;
  174. }
  175. /**
  176. * Return path for skin images placeholder
  177. *
  178. * @return string
  179. */
  180. public function getSkinImagePlaceholderPath()
  181. {
  182. $staticPath = $this->_storeManager->getStore()->getBaseStaticDir();
  183. $placeholderPath = $this->_assetRepo->createAsset(self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID)->getPath();
  184. return $staticPath . '/' . $placeholderPath;
  185. }
  186. /**
  187. * Check whether Wysiwyg is enabled or not
  188. *
  189. * @return bool
  190. */
  191. public function isEnabled()
  192. {
  193. $wysiwygState = $this->_scopeConfig->getValue(
  194. self::WYSIWYG_STATUS_CONFIG_PATH,
  195. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  196. $this->getStoreId()
  197. );
  198. return in_array($wysiwygState, [self::WYSIWYG_ENABLED, self::WYSIWYG_HIDDEN]);
  199. }
  200. /**
  201. * Check whether Wysiwyg is loaded on demand or not
  202. *
  203. * @return bool
  204. */
  205. public function isHidden()
  206. {
  207. $status = $this->_scopeConfig->getValue(
  208. self::WYSIWYG_STATUS_CONFIG_PATH,
  209. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  210. );
  211. return $status == self::WYSIWYG_HIDDEN;
  212. }
  213. }