77
88use Magento \Framework \Serialize \Serializer \Json ;
99use Magento \Framework \Setup \SampleData \Context as SampleDataContext ;
10+ use \Magento \Framework \App \State ;
1011
1112/**
1213 * Launches setup of sample data for Widget module
@@ -53,6 +54,11 @@ class CmsBlock
5354 */
5455 private $ serializer ;
5556
57+ /**
58+ * @var State
59+ */
60+ private $ appState ;
61+
5662 /**
5763 * @param SampleDataContext $sampleDataContext
5864 * @param \Magento\Widget\Model\Widget\InstanceFactory $widgetFactory
@@ -61,6 +67,7 @@ class CmsBlock
6167 * @param \Magento\Widget\Model\ResourceModel\Widget\Instance\CollectionFactory $appCollectionFactory
6268 * @param \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryFactory
6369 * @param Json|null $serializer
70+ * @param State|null $appState
6471 */
6572 public function __construct (
6673 SampleDataContext $ sampleDataContext ,
@@ -69,7 +76,8 @@ public function __construct(
6976 \Magento \Cms \Model \BlockFactory $ cmsBlockFactory ,
7077 \Magento \Widget \Model \ResourceModel \Widget \Instance \CollectionFactory $ appCollectionFactory ,
7178 \Magento \Catalog \Model \ResourceModel \Category \CollectionFactory $ categoryFactory ,
72- Json $ serializer = null
79+ Json $ serializer = null ,
80+ State $ appState = null
7381 ) {
7482 $ this ->fixtureManager = $ sampleDataContext ->getFixtureManager ();
7583 $ this ->csvReader = $ sampleDataContext ->getCsvReader ();
@@ -79,6 +87,7 @@ public function __construct(
7987 $ this ->appCollectionFactory = $ appCollectionFactory ;
8088 $ this ->categoryFactory = $ categoryFactory ;
8189 $ this ->serializer = $ serializer ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (Json::class);
90+ $ this ->appState = $ appState ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (State::class);
8291 }
8392
8493 /**
@@ -163,7 +172,10 @@ public function install(array $fixtures)
163172 ->setStoreIds ([\Magento \Store \Model \Store::DEFAULT_STORE_ID ])
164173 ->setWidgetParameters (['block_id ' => $ block ->getId ()])
165174 ->setPageGroups ([$ pageGroup ]);
166- $ widgetInstance ->save ();
175+ $ this ->appState ->emulateAreaCode (
176+ 'frontend ' ,
177+ [$ widgetInstance , 'save ' ]
178+ );
167179 }
168180 }
169181 }
0 commit comments