Skip to content

Commit 8aaa9e9

Browse files
MC-37653: New/Edit Dynamic Block with Different User Role
1 parent 1e2bcad commit 8aaa9e9

File tree

1 file changed

+50
-29
lines changed

1 file changed

+50
-29
lines changed

app/code/Magento/PageBuilder/Model/Stage/Preview.php

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,46 @@
77

88
namespace Magento\PageBuilder\Model\Stage;
99

10+
use Magento\Framework\App\Area;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\App\State;
13+
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
14+
use Magento\Framework\View\DesignInterface;
15+
use Magento\Store\Model\App\Emulation;
16+
use Magento\Store\Model\StoreManagerInterface;
17+
1018
/**
1119
* Handle placing Magento into Page Builder Preview mode and emulating the store front
1220
*/
1321
class Preview
1422
{
1523
/**
16-
* @var \Magento\Store\Model\App\Emulation
24+
* @var Emulation
1725
*/
1826
private $emulation;
1927

2028
/**
21-
* @var \Magento\Framework\App\State
29+
* @var State
2230
*/
2331
private $appState;
2432

2533
/**
26-
* @var \Magento\Framework\View\DesignInterface
34+
* @var DesignInterface
2735
*/
2836
private $design;
2937

3038
/**
31-
* @var \Magento\Framework\View\Design\Theme\ThemeProviderInterface
39+
* @var ThemeProviderInterface
3240
*/
3341
private $themeProvider;
3442

3543
/**
36-
* @var \Magento\Store\Model\StoreManagerInterface
44+
* @var StoreManagerInterface
3745
*/
3846
private $storeManager;
3947

4048
/**
41-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
49+
* @var ScopeConfigInterface
4250
*/
4351
private $scopeConfig;
4452

@@ -49,20 +57,20 @@ class Preview
4957

5058
/**
5159
* Preview constructor.
52-
* @param \Magento\Store\Model\App\Emulation $emulation
53-
* @param \Magento\Framework\App\State $appState
54-
* @param \Magento\Framework\View\DesignInterface $design
55-
* @param \Magento\Framework\View\Design\Theme\ThemeProviderInterface $themeProvider
56-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
57-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
60+
* @param Emulation $emulation
61+
* @param State $appState
62+
* @param DesignInterface $design
63+
* @param ThemeProviderInterface $themeProvider
64+
* @param StoreManagerInterface $storeManager
65+
* @param ScopeConfigInterface $scopeConfig
5866
*/
5967
public function __construct(
60-
\Magento\Store\Model\App\Emulation $emulation,
61-
\Magento\Framework\App\State $appState,
62-
\Magento\Framework\View\DesignInterface $design,
63-
\Magento\Framework\View\Design\Theme\ThemeProviderInterface $themeProvider,
64-
\Magento\Store\Model\StoreManagerInterface $storeManager,
65-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
68+
Emulation $emulation,
69+
State $appState,
70+
DesignInterface $design,
71+
ThemeProviderInterface $themeProvider,
72+
StoreManagerInterface $storeManager,
73+
ScopeConfigInterface $scopeConfig
6674
) {
6775
$this->emulation = $emulation;
6876
$this->appState = $appState;
@@ -79,7 +87,7 @@ public function __construct(
7987
*/
8088
public function getPreviewArea() : string
8189
{
82-
return \Magento\Framework\App\Area::AREA_FRONTEND;
90+
return Area::AREA_FRONTEND;
8391
}
8492

8593
/**
@@ -95,16 +103,7 @@ public function startPreviewMode($callback, $storeId = null)
95103
$this->isPreview = true;
96104

97105
if (!$storeId) {
98-
$store = $this->storeManager->getDefaultStoreView();
99-
if ($store) {
100-
$storeId = $store->getId();
101-
} else {
102-
$stores = $this->storeManager->getStores();
103-
if (count($stores)) {
104-
$store = array_shift($stores);
105-
$storeId = $store->getId();
106-
}
107-
}
106+
$storeId = $this->getStoreId();
108107
}
109108
$this->emulation->startEnvironmentEmulation($storeId);
110109

@@ -140,4 +139,26 @@ public function isPreviewMode() : bool
140139
{
141140
return $this->isPreview;
142141
}
142+
143+
/**
144+
* Returns store id by default store view or store id from the available store if default store view is null
145+
*
146+
* @return int|null
147+
*/
148+
private function getStoreId(): ?int
149+
{
150+
$storeId = null;
151+
$store = $this->storeManager->getDefaultStoreView();
152+
if ($store) {
153+
$storeId = $store->getId();
154+
} else {
155+
$stores = $this->storeManager->getStores();
156+
if (count($stores)) {
157+
$store = array_shift($stores);
158+
$storeId = $store->getId();
159+
}
160+
}
161+
162+
return $storeId;
163+
}
143164
}

0 commit comments

Comments
 (0)