/** * Retrieve additional html and put it at the end of element html * * @return string */ public function getAfterElementHtml() { $html = parent::getAfterElementHtml(); if ($this->getIsWysiwygEnabled()) { $disabled = $this->getDisabled() || $this->getReadonly(); $html .= $this->_layout->createBlock('Magento\\Backend\\Block\\Widget\\Button', '', array('data' => array('label' => __('WYSIWYG Editor'), 'type' => 'button', 'disabled' => $disabled, 'class' => $disabled ? 'disabled action-wysiwyg' : 'action-wysiwyg', 'onclick' => 'catalogWysiwygEditor.open(\'' . $this->_backendData->getUrl('catalog/product/wysiwyg') . '\', \'' . $this->getHtmlId() . '\')')))->toHtml(); $html .= <<<HTML <script type="text/javascript"> jQuery('#{$this->getHtmlId()}') .addClass('wysiwyg-editor') .data( 'wysiwygEditor', new tinyMceWysiwygSetup( '{$this->getHtmlId()}', { settings: { theme_advanced_buttons1 : 'bold,italic,|,justifyleft,justifycenter,justifyright,|,' + 'fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code', theme_advanced_buttons2: null, theme_advanced_buttons3: null, theme_advanced_buttons4: null, theme_advanced_statusbar_location: null } } ).turnOn() ); </script> HTML; } return $html; }
/** * 2016-03-09 * @override * @see \Magento\Framework\Data\Form\AbstractForm::_construct() * https://github.com/magento/magento2/blob/487f5f45/lib/internal/Magento/Framework/Data/Form/AbstractForm.php#L64-L73 * @return void * * Перекрывать надо именно этот метод, а не getRows(), * потому что @see \Magento\Framework\Data\Form\AbstractForm::serialize() * не вызывает методы-аксессоры, а напрямую работает с @see \Magento\Framework\DataObject::$_data * https://github.com/magento/magento2/blob/487f5f45/lib/internal/Magento/Framework/Data/Form/AbstractForm.php#L256-L260 * * https://github.com/mage2pro/core/tree/34f8c108/Config/etc/system_file.xsd#L102 * https://code.dmitry-fedyuk.com/m2e/twitter-timeline/blob/604c28e/etc/adminhtml/system.xml#L50 */ protected function _construct() { parent::_construct(); /** @var int $dfRows */ $dfRows = df_fe_fc_i($this, 'dfRows'); if ($dfRows) { $this['rows'] = $dfRows; } }
public function __construct(\Magento\Framework\Data\Form\Element\Factory $factoryElement, \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, Config $wysiwygConfig, Escaper $escaper, $data = []) { parent::__construct($factoryElement, $factoryCollection, $escaper, $data); $this->setType('textarea'); $this->setExtType('textarea'); $config = $wysiwygConfig->getConfig(); $config->setEncodeDirectives(false); $config->setNoDisplay(true); $config->setFilesBrowserWindowWidth(100); $this->setConfig($config); }
/** * Retrieve additional html and put it at the end of element html * * @return string */ public function getAfterElementHtml() { $config = $this->_wysiwygConfig->getConfig(); $config = json_encode($config->getData()); $html = parent::getAfterElementHtml(); if ($this->getIsWysiwygEnabled()) { $disabled = $this->getDisabled() || $this->getReadonly(); $html .= $this->_layout->createBlock('Magento\\Backend\\Block\\Widget\\Button', '', ['data' => ['label' => __('WYSIWYG Editor'), 'type' => 'button', 'disabled' => $disabled, 'class' => 'action-wysiwyg', 'onclick' => 'catalogWysiwygEditor.open(\'' . $this->_backendData->getUrl('catalog/product/wysiwyg') . '\', \'' . $this->getHtmlId() . '\')']])->toHtml(); $html .= <<<HTML <script> require([ 'jquery', 'mage/adminhtml/wysiwyg/tiny_mce/setup' ], function(jQuery){ var config = {$config}, editor; jQuery.extend(config, { settings: { theme_advanced_buttons1 : 'bold,italic,|,justifyleft,justifycenter,justifyright,|,' + 'fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code', theme_advanced_buttons2: null, theme_advanced_buttons3: null, theme_advanced_buttons4: null, theme_advanced_statusbar_location: null }, files_browser_window_url: false }); editor = new tinyMceWysiwygSetup( '{$this->getHtmlId()}', config ); editor.turnOn(); jQuery('#{$this->getHtmlId()}') .addClass('wysiwyg-editor') .data( 'wysiwygEditor', editor ); }); </script> HTML; } return $html; }
/** * @covers \Magento\Framework\Data\Form\Element\Textarea::getHtmlAttributes */ public function testGetHtmlAttributes() { $this->assertEmpty(array_diff(['title', 'class', 'style', 'onclick', 'onchange', 'rows', 'cols', 'readonly', 'disabled', 'onkeyup', 'tabindex'], $this->_model->getHtmlAttributes())); }
/** * @return string */ public function getElementHtml() { $js = ' <script type="text/javascript"> //<![CDATA[ openEditorPopup = function(url, name, specs, parent) { if ((typeof popups == "undefined") || popups[name] == undefined || popups[name].closed) { if (typeof popups == "undefined") { popups = new Array(); } var opener = (parent != undefined ? parent : window); popups[name] = opener.open(url, name, specs); } else { popups[name].focus(); } return popups[name]; } closeEditorPopup = function(name) { if ((typeof popups != "undefined") && popups[name] != undefined && !popups[name].closed) { popups[name].close(); } } //]]> </script>'; if ($this->isEnabled()) { // add Firebug notice translations $warn = 'Firebug is known to make the WYSIWYG editor slow unless it is turned off or configured properly.'; $this->getConfig()->addData(array('firebug_warning_title' => $this->translate('Warning'), 'firebug_warning_text' => $this->translate($warn), 'firebug_warning_anchor' => $this->translate('Hide'))); $translatedString = array('Insert Image...' => $this->translate('Insert Image...'), 'Insert Media...' => $this->translate('Insert Media...'), 'Insert File...' => $this->translate('Insert File...')); $jsSetupObject = 'wysiwyg' . $this->getHtmlId(); $forceLoad = ''; if (!$this->isHidden()) { if ($this->getForceLoad()) { $forceLoad = $jsSetupObject . '.setup("exact");'; } else { $forceLoad = 'Event.observe(window, "load", ' . $jsSetupObject . '.setup.bind(' . $jsSetupObject . ', "exact"));'; } } $html = $this->_getButtonsHtml() . '<textarea name="' . $this->getName() . '" title="' . $this->getTitle() . '" ' . $this->_getUiId() . ' id="' . $this->getHtmlId() . '"' . ' class="textarea' . $this->getClass() . '" ' . $this->serialize($this->getHtmlAttributes()) . ' >' . $this->getEscapedValue() . '</textarea>' . $js . ' <script type="text/javascript"> //<![CDATA[' . "\n" . '(function($) {$.mage.translate.add(' . \Zend_Json::encode($translatedString) . ')})(jQuery);' . "\n" . $jsSetupObject . ' = new tinyMceWysiwygSetup("' . $this->getHtmlId() . '", ' . \Zend_Json::encode($this->getConfig()) . ');' . $forceLoad . ' editorFormValidationHandler = ' . $jsSetupObject . '.onFormValidation.bind(' . $jsSetupObject . '); Event.observe("toggle' . $this->getHtmlId() . '", "click", ' . $jsSetupObject . '.toggle.bind(' . $jsSetupObject . ')); varienGlobalEvents.attachEventHandler("formSubmit", editorFormValidationHandler); varienGlobalEvents.attachEventHandler("tinymceBeforeSetContent", ' . $jsSetupObject . '.beforeSetContent.bind(' . $jsSetupObject . ')); varienGlobalEvents.attachEventHandler("tinymceSaveContent", ' . $jsSetupObject . '.saveContent.bind(' . $jsSetupObject . ')); varienGlobalEvents.clearEventHandlers("open_browser_callback"); varienGlobalEvents.attachEventHandler("open_browser_callback", ' . $jsSetupObject . '.openFileBrowser.bind(' . $jsSetupObject . ')); //]]> </script>'; $html = $this->_wrapIntoContainer($html); $html .= $this->getAfterElementHtml(); return $html; } else { // Display only buttons to additional features if ($this->getConfig('widget_window_url')) { $html = $this->_getButtonsHtml() . $js . parent::getElementHtml(); $html = $this->_wrapIntoContainer($html); return $html; } return parent::getElementHtml(); } }
/** * @return string * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function getElementHtml() { $js = ' <script type="text/javascript"> //<![CDATA[ openEditorPopup = function(url, name, specs, parent) { if ((typeof popups == "undefined") || popups[name] == undefined || popups[name].closed) { if (typeof popups == "undefined") { popups = new Array(); } var opener = (parent != undefined ? parent : window); popups[name] = opener.open(url, name, specs); } else { popups[name].focus(); } return popups[name]; } closeEditorPopup = function(name) { if ((typeof popups != "undefined") && popups[name] != undefined && !popups[name].closed) { popups[name].close(); } } //]]> </script>'; if ($this->isEnabled()) { $jsSetupObject = 'wysiwyg' . $this->getHtmlId(); $forceLoad = ''; if (!$this->isHidden()) { if ($this->getForceLoad()) { $forceLoad = $jsSetupObject . '.setup("exact");'; } else { $forceLoad = 'Event.observe(window, "load", ' . $jsSetupObject . '.setup.bind(' . $jsSetupObject . ', "exact"));'; } } $html = $this->_getButtonsHtml() . '<textarea name="' . $this->getName() . '" title="' . $this->getTitle() . '" ' . $this->_getUiId() . ' id="' . $this->getHtmlId() . '"' . ' class="textarea' . $this->getClass() . '" ' . $this->serialize($this->getHtmlAttributes()) . ' >' . $this->getEscapedValue() . '</textarea>' . $js . ' <script type="text/javascript"> //<![CDATA[ require(["jquery", "mage/translate", "mage/adminhtml/events", "mage/adminhtml/wysiwyg/tiny_mce/setup", "mage/adminhtml/wysiwyg/widget"], function(jQuery){' . "\n" . '(function($) {$.mage.translate.add(' . \Zend_Json::encode($this->getButtonTranslations()) . ')})(jQuery);' . "\n" . $jsSetupObject . ' = new tinyMceWysiwygSetup("' . $this->getHtmlId() . '", ' . \Zend_Json::encode($this->getConfig()) . ');' . $forceLoad . ' editorFormValidationHandler = ' . $jsSetupObject . '.onFormValidation.bind(' . $jsSetupObject . '); Event.observe("toggle' . $this->getHtmlId() . '", "click", ' . $jsSetupObject . '.toggle.bind(' . $jsSetupObject . ')); varienGlobalEvents.attachEventHandler("formSubmit", editorFormValidationHandler); varienGlobalEvents.clearEventHandlers("open_browser_callback"); varienGlobalEvents.attachEventHandler("open_browser_callback", ' . $jsSetupObject . '.openFileBrowser); //]]> }); </script>'; $html = $this->_wrapIntoContainer($html); $html .= $this->getAfterElementHtml(); return $html; } else { // Display only buttons to additional features if ($this->getConfig('widget_window_url')) { $html = $this->_getButtonsHtml() . $js . parent::getElementHtml(); if ($this->getConfig('add_widgets')) { $html .= '<script type="text/javascript"> //<![CDATA[ require(["jquery", "mage/translate", "mage/adminhtml/wysiwyg/widget"], function(jQuery){ (function($) { $.mage.translate.add(' . \Zend_Json::encode($this->getButtonTranslations()) . ') })(jQuery); }); //]]> </script>'; } $html = $this->_wrapIntoContainer($html); return $html; } return parent::getElementHtml(); } }