Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Wysiwyg.php
Go to the documentation of this file.
1 <?php
13 
14 class Wysiwyg extends \Magento\Framework\Data\Form\Element\Textarea
15 {
21  protected $_backendData = null;
22 
28  protected $_moduleManager = null;
29 
33  protected $_wysiwygConfig;
34 
38  protected $_layout;
39 
50  public function __construct(
51  \Magento\Framework\Data\Form\Element\Factory $factoryElement,
52  \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection,
53  \Magento\Framework\Escaper $escaper,
54  \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
55  \Magento\Framework\View\LayoutInterface $layout,
56  \Magento\Framework\Module\Manager $moduleManager,
57  \Magento\Backend\Helper\Data $backendData,
58  array $data = []
59  ) {
60  $this->_wysiwygConfig = $wysiwygConfig;
61  $this->_layout = $layout;
62  $this->_moduleManager = $moduleManager;
63  $this->_backendData = $backendData;
64  parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
65  }
66 
72  public function getAfterElementHtml()
73  {
74  $config = $this->_wysiwygConfig->getConfig();
75  $config = json_encode($config->getData());
76 
77  $html = parent::getAfterElementHtml();
78  if ($this->getIsWysiwygEnabled()) {
79  $disabled = $this->getDisabled() || $this->getReadonly();
80  $html .= $this->_layout->createBlock(
81  \Magento\Backend\Block\Widget\Button::class,
82  '',
83  [
84  'data' => [
85  'label' => __('WYSIWYG Editor'),
86  'type' => 'button',
87  'disabled' => $disabled,
88  'class' => 'action-wysiwyg',
89  'onclick' => 'catalogWysiwygEditor.open(\'' . $this->_backendData->getUrl(
90  'catalog/product/wysiwyg'
91  ) . '\', \'' . $this->getHtmlId() . '\')',
92  ]
93  ]
94  )->toHtml();
95  $html .= <<<HTML
96 <script>
97 require([
98  'jquery',
99  'mage/adminhtml/wysiwyg/tiny_mce/setup'
100 ], function(jQuery){
101 
102 var config = $config,
103  editor;
104 
105 editor = new wysiwygSetup(
106  '{$this->getHtmlId()}',
107  config
108 );
109 
110 editor.turnOn();
111 
112 jQuery('#{$this->getHtmlId()}')
113  .addClass('wysiwyg-editor')
114  .data(
115  'wysiwygEditor',
116  editor
117  );
118 });
119 </script>
120 HTML;
121  }
122  return $html;
123  }
124 
131  public function getIsWysiwygEnabled()
132  {
133  if ($this->_moduleManager->isEnabled('Magento_Cms')) {
134  return (bool)($this->_wysiwygConfig->isEnabled() && $this->getEntityAttribute()->getIsWysiwygEnabled());
135  }
136 
137  return false;
138  }
139 }
__construct(\Magento\Framework\Data\Form\Element\Factory $factoryElement, \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, \Magento\Framework\Escaper $escaper, \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, \Magento\Framework\View\LayoutInterface $layout, \Magento\Framework\Module\Manager $moduleManager, \Magento\Backend\Helper\Data $backendData, array $data=[])
Definition: Wysiwyg.php:50
$config
Definition: fraud_order.php:17
if( $form)() ?>< script > require(['jquery' mage mage
Definition: save.phtml:15
__()
Definition: __.php:13
$moduleManager
Definition: products.php:75