Skip to content

Commit 2d36ee0

Browse files
ENGCOM-6329: Added 'clearEvent' to eventBus to prevent multiple attach event on wysiwyg editor #25671
2 parents 83d9d7c + cdf6286 commit 2d36ee0

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

app/code/Magento/Tinymce3/view/base/web/tinymce3Adapter.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ define([
7878
}
7979

8080
tinyMCE3.init(this.getSettings(mode));
81+
varienGlobalEvents.clearEventHandlers('open_browser_callback');
82+
varienGlobalEvents.attachEventHandler('open_browser_callback', tinyMceEditors.get(this.id).openFileBrowser);
8183
},
8284

8385
/**
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'wysiwygAdapter',
8+
'underscore'
9+
], function (wysiwygAdapter, _) {
10+
'use strict';
11+
12+
var obj;
13+
14+
beforeEach(function () {
15+
16+
/**
17+
* Dummy constructor to use for instantiation
18+
* @constructor
19+
*/
20+
var Constr = function () {};
21+
22+
Constr.prototype = wysiwygAdapter;
23+
24+
obj = new Constr();
25+
obj.eventBus = new window.varienEvents();
26+
obj.initialize(1, {
27+
'store_id': 0,
28+
'tinymce4': {
29+
'content_css': ''
30+
},
31+
'files_browser_window_url': 'url'
32+
});
33+
obj.setup();
34+
});
35+
36+
describe('"openFileBrowser" method', function () {
37+
it('Opens file browser to given instance', function () {
38+
expect(_.size(obj.eventBus.arrEvents['open_browser_callback'])).toBe(1);
39+
});
40+
});
41+
});

lib/internal/Magento/Framework/Data/Form/Element/Editor.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ protected function _getPluginButtonsHtml($visible = true)
310310
if (isset($buttonOptions['style'])) {
311311
$configStyle = $buttonOptions['style'];
312312
}
313-
$buttonOptions = array_merge($buttonOptions, ['style' => 'display:none;' . $configStyle]);
313+
$buttonOptions['style'] = 'display:none; ' . $configStyle;
314314
}
315315
$buttonsHtml .= $this->_getButtonHtml($buttonOptions);
316316
}
@@ -409,7 +409,7 @@ protected function _getButtonHtml($data)
409409
protected function _wrapIntoContainer($html)
410410
{
411411
if (!$this->getConfig('use_container')) {
412-
return '<div class="admin__control-wysiwig">' .$html . '</div>';
412+
return '<div class="admin__control-wysiwig">' . $html . '</div>';
413413
}
414414

415415
$html = '<div id="editor' . $this->getHtmlId() . '"'
@@ -533,10 +533,6 @@ protected function getInlineJs($jsSetupObject, $forceLoad)
533533
$jsSetupObject .
534534
'));
535535
varienGlobalEvents.attachEventHandler("formSubmit", editorFormValidationHandler);
536-
varienGlobalEvents.clearEventHandlers("open_browser_callback");
537-
varienGlobalEvents.attachEventHandler("open_browser_callback", ' .
538-
$jsSetupObject .
539-
'.openFileBrowser);
540536
//]]>
541537
});
542538
</script>';

lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ define([
118118
tinyMCE4.init(settings);
119119
this.getPluginButtons().hide();
120120
varienGlobalEvents.clearEventHandlers('open_browser_callback');
121+
this.eventBus.clearEventHandlers('open_browser_callback');
121122
this.eventBus.attachEventHandler('open_browser_callback', tinyMceEditors.get(self.id).openFileBrowser);
122123
}.bind(this));
123124
},

0 commit comments

Comments
 (0)