Widget.php 1.69 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Widget\Block\Adminhtml;

/**
 * WYSIWYG widget plugin main block
 *
 * @api
 * @since 100.0.2
 */
class Widget extends \Magento\Backend\Block\Widget\Form\Container
{
    /**
     * @inheritdoc
     */
    protected function _construct()
    {
        parent::_construct();

        $this->_blockGroup = 'Magento_Widget';
        $this->_controller = 'adminhtml';
        $this->_mode = 'widget';
        $this->_headerText = __('Widget Insertion');

        $saveButtonClass = 'action-primary add-widget';
        $this->removeButton('back');
        if ($this->getRequest()->getParam('mode') === 'new') {
            $this->buttonList->update('save', 'label', __('Insert Widget'));
            $saveButtonClass .= ' disabled';
        }
        $this->buttonList->update('save', 'class', $saveButtonClass);
        $this->buttonList->update('save', 'id', 'insert_button');
        $this->buttonList->update('save', 'onclick', 'wWidget.insertWidget()');
        $this->buttonList->update('save', 'region', 'toolbar');
        $this->buttonList->update('save', 'data_attribute', []);
        $this->buttonList->update('reset', 'label', __('Cancel'));
        $this->buttonList->update('reset', 'onclick', 'wWidget.closeModal()');

        $this->_formScripts[] = <<<EOJS
require(['mage/adminhtml/wysiwyg/widget'], function() {
    wWidget = new WysiwygWidget.Widget(
        'widget_options_form',
        'select_widget_type',
        'widget_options',
        '{$this->getUrl('adminhtml/*/loadOptions')}',
        '{$this->escapeJs($this->getRequest()->getParam('widget_target_id'))}'
    );
});
EOJS;
    }
}