I have a custom module for megamenu. I want to create some widgets predefined for the module when the customer installs this module. I have added the below script for creating the widget(widget type: cms block)
This is my InstallData.php
namespace Vendor\MegaMenu\Setup;
use Magento\Framework\Setup;
class InstallData implements Setup\InstallDataInterface
{
/**
* @var Setup\SampleData\Executor
*/
protected $executor;
/**
* @var Installer
*/
protected $installer;
private $widgetFactory;
public function __construct(
Setup\SampleData\Executor $executor,
Installer $installer,
\Magento\Widget\Model\Widget\InstanceFactory $widgetFactory
)
{
$this->executor = $executor;
$this->installer = $installer;
$this->widgetFactory = $widgetFactory;
}
public function install(Setup\ModuleDataSetupInterface $setup, Setup\ModuleContextInterface $moduleContext)
{
$this->executor->exec($this->installer);
$megaMenuWidget = [
'instance_type' => 'Magento\Cms\Block\Widget\Block',
'theme_id' => 2,
'title' => 'Test Megamenu Horizontal',
'store_ids' => '0',
'widget_parameters' => 'a:1:{s:8:"block_id";s:1:"11";}',
'sort_order' => 1
];
$this->widgetFactory->create()->setData($megaMenuWidget)->save();
}
}
The widget is created. But not able to set layout update field and assign static block. Please refer the screenshot
http://i.prntscr.com/NEp1Nu_wToOwDCJYlQR_-g.png
How can I create a widget using upgrade script? My Magento version is 2.1.x
Please help me with a solution...