I am wanting to do custom javascript to manipulate the Widget Options when adding a widget (using the WYSIWYG editor) in the Admin panel.
I have found that the layout handle adminhtml_widget_index
is being loaded via AJAX to get that content, however, I have noticed that any script tags in my template file are being removed.
For demonstration purposes the phtml file I am using looks like
// Module_Vendor::test.phtml
<?php
/** @var \Magento\Backend\Block\Template $block */
?>
<h2>Modal windows strip custom js...</h2>
<script>
alert('Just kidding, JAVASCRIPT works in modals');
</script>
I have the <h2>
tag showing on the widget modal form, but looking at the source there is no script tag.
Looking further into how the widget renders, using the \Magento\Widget\Block\Adminhtml\Widget
class, there is a protected $_formScripts
array that might be used with a plugin which could solve the issue, however I'm wondering if there is another way to render custom javascript on the Insert Widget modal form?
If anyone has any useful information, I'd be delighted to hear it.
Thanks in advance!
As a side note there is an initialisation of the wysiwyg widget javascript component which is added as a string to the $_formScripts
array, which doesn't seem like best practice, so even if using the $_formScripts
array is how we should do it, if you could provide an example of how, that would also be fantastic!