Skip to content

Commit 9a988b5

Browse files
committed
MAGETWO-93061: CMS page of second website with same URLkey as first website, show content of First website instead of second website content.
- Fix CR comments
1 parent f2aeeb8 commit 9a988b5

File tree

4 files changed

+132
-63
lines changed

4 files changed

+132
-63
lines changed

app/code/Magento/Cms/Block/Adminhtml/Page/Grid/Renderer/Action/UrlBuilder.php

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
declare(strict_types=1);
7-
86
namespace Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action;
97

10-
use Magento\Framework\App\ObjectManager;
11-
use Magento\Framework\Url\EncoderInterface;
12-
use Magento\Framework\App\ActionInterface;
13-
use Magento\Store\Model\StoreManagerInterface;
14-
158
/**
169
* Url builder class used to compose dynamic urls.
1710
*/
@@ -22,31 +15,12 @@ class UrlBuilder
2215
*/
2316
protected $frontendUrlBuilder;
2417

25-
/**
26-
* @var EncoderInterface
27-
*/
28-
private $urlEncoder;
29-
30-
/**
31-
* @var StoreManagerInterface
32-
*/
33-
private $storeManager;
34-
3518
/**
3619
* @param \Magento\Framework\UrlInterface $frontendUrlBuilder
37-
* @param EncoderInterface|null $urlEncoder
38-
* @param StoreManagerInterface|null $storeManager
3920
*/
40-
public function __construct(
41-
\Magento\Framework\UrlInterface $frontendUrlBuilder,
42-
EncoderInterface $urlEncoder = null,
43-
StoreManagerInterface $storeManager = null
44-
) {
21+
public function __construct(\Magento\Framework\UrlInterface $frontendUrlBuilder)
22+
{
4523
$this->frontendUrlBuilder = $frontendUrlBuilder;
46-
$this->urlEncoder = $urlEncoder ?: ObjectManager::getInstance()
47-
->get(EncoderInterface::class);
48-
$this->storeManager = $storeManager?: ObjectManager::getInstance()
49-
->get(StoreManagerInterface::class);
5024
}
5125

5226
/**
@@ -61,22 +35,12 @@ public function getUrl($routePath, $scope, $store)
6135
{
6236
if ($scope) {
6337
$this->frontendUrlBuilder->setScope($scope);
64-
$targetUrl = $this->frontendUrlBuilder->getUrl(
65-
$routePath,
66-
[
67-
'_current' => false,
68-
'_nosid' => true,
69-
'_query' => [
70-
StoreManagerInterface::PARAM_NAME => $store
71-
]
72-
]
73-
);
7438
$href = $this->frontendUrlBuilder->getUrl(
75-
'stores/store/switch',
39+
$routePath,
7640
[
7741
'_current' => false,
7842
'_nosid' => true,
79-
'_query' => $this->prepareRequestQuery($store, $targetUrl)
43+
'_query' => [\Magento\Store\Model\StoreManagerInterface::PARAM_NAME => $store]
8044
]
8145
);
8246
} else {
@@ -91,25 +55,4 @@ public function getUrl($routePath, $scope, $store)
9155

9256
return $href;
9357
}
94-
95-
/**
96-
* Prepare request query
97-
*
98-
* @param string $store
99-
* @param string $href
100-
* @return array
101-
*/
102-
private function prepareRequestQuery(string $store, string $href) : array
103-
{
104-
$storeView = $this->storeManager->getDefaultStoreView();
105-
$query = [
106-
StoreManagerInterface::PARAM_NAME => $store,
107-
ActionInterface::PARAM_NAME_URL_ENCODED => $this->urlEncoder->encode($href)
108-
];
109-
if ($storeView->getCode() !== $store) {
110-
$query['___from_store'] = $storeView->getCode();
111-
}
112-
113-
return $query;
114-
}
11558
}

app/code/Magento/Cms/Ui/Component/Listing/Column/PageActions.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class PageActions extends Column
2727
*/
2828
protected $actionUrlBuilder;
2929

30+
/**
31+
* @var \Magento\Cms\ViewModel\Page\Grid\UrlBuilder
32+
*/
33+
private $scopeUrlBuilder;
34+
3035
/**
3136
* @var \Magento\Framework\UrlInterface
3237
*/
@@ -50,6 +55,7 @@ class PageActions extends Column
5055
* @param array $components
5156
* @param array $data
5257
* @param string $editUrl
58+
* @param \Magento\Cms\ViewModel\Page\Grid\UrlBuilder|null $scopeUrlBuilder
5359
*/
5460
public function __construct(
5561
ContextInterface $context,
@@ -58,12 +64,15 @@ public function __construct(
5864
UrlInterface $urlBuilder,
5965
array $components = [],
6066
array $data = [],
61-
$editUrl = self::CMS_URL_PATH_EDIT
67+
$editUrl = self::CMS_URL_PATH_EDIT,
68+
\Magento\Cms\ViewModel\Page\Grid\UrlBuilder $scopeUrlBuilder = null
6269
) {
6370
$this->urlBuilder = $urlBuilder;
6471
$this->actionUrlBuilder = $actionUrlBuilder;
6572
$this->editUrl = $editUrl;
6673
parent::__construct($context, $uiComponentFactory, $components, $data);
74+
$this->scopeUrlBuilder = $scopeUrlBuilder ?: ObjectManager::getInstance()
75+
->get(\Magento\Cms\ViewModel\Page\Grid\UrlBuilder::class);
6776
}
6877

6978
/**
@@ -92,7 +101,7 @@ public function prepareDataSource(array $dataSource)
92101
}
93102
if (isset($item['identifier'])) {
94103
$item[$name]['preview'] = [
95-
'href' => $this->actionUrlBuilder->getUrl(
104+
'href' => $this->scopeUrlBuilder->getUrl(
96105
$item['identifier'],
97106
isset($item['_first_store_id']) ? $item['_first_store_id'] : null,
98107
isset($item['store_code']) ? $item['store_code'] : null
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Cms\ViewModel\Page\Grid;
9+
10+
use Magento\Framework\Url\EncoderInterface;
11+
use Magento\Framework\App\ActionInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
14+
/**
15+
* Url builder class used to compose dynamic urls.
16+
*/
17+
class UrlBuilder
18+
{
19+
/**
20+
* @var \Magento\Framework\UrlInterface
21+
*/
22+
protected $frontendUrlBuilder;
23+
24+
/**
25+
* @var EncoderInterface
26+
*/
27+
private $urlEncoder;
28+
29+
/**
30+
* @var StoreManagerInterface
31+
*/
32+
private $storeManager;
33+
34+
/**
35+
* @param \Magento\Framework\UrlInterface $frontendUrlBuilder
36+
* @param EncoderInterface $urlEncoder
37+
* @param StoreManagerInterface $storeManager
38+
*/
39+
public function __construct(
40+
\Magento\Framework\UrlInterface $frontendUrlBuilder,
41+
EncoderInterface $urlEncoder,
42+
StoreManagerInterface $storeManager
43+
) {
44+
$this->frontendUrlBuilder = $frontendUrlBuilder;
45+
$this->urlEncoder = $urlEncoder;
46+
$this->storeManager = $storeManager;
47+
}
48+
49+
/**
50+
* Get action url
51+
*
52+
* @param string $routePath
53+
* @param string $scope
54+
* @param string $store
55+
* @return string
56+
*/
57+
public function getUrl($routePath, $scope, $store)
58+
{
59+
if ($scope) {
60+
$this->frontendUrlBuilder->setScope($scope);
61+
$targetUrl = $this->frontendUrlBuilder->getUrl(
62+
$routePath,
63+
[
64+
'_current' => false,
65+
'_nosid' => true,
66+
'_query' => [
67+
StoreManagerInterface::PARAM_NAME => $store
68+
]
69+
]
70+
);
71+
$href = $this->frontendUrlBuilder->getUrl(
72+
'stores/store/switch',
73+
[
74+
'_current' => false,
75+
'_nosid' => true,
76+
'_query' => $this->prepareRequestQuery($store, $targetUrl)
77+
]
78+
);
79+
} else {
80+
$href = $this->frontendUrlBuilder->getUrl(
81+
$routePath,
82+
[
83+
'_current' => false,
84+
'_nosid' => true
85+
]
86+
);
87+
}
88+
89+
return $href;
90+
}
91+
92+
/**
93+
* Prepare request query
94+
*
95+
* @param string $store
96+
* @param string $href
97+
* @return array
98+
*/
99+
private function prepareRequestQuery(string $store, string $href) : array
100+
{
101+
$storeView = $this->storeManager->getDefaultStoreView();
102+
$query = [
103+
StoreManagerInterface::PARAM_NAME => $store,
104+
ActionInterface::PARAM_NAME_URL_ENCODED => $this->urlEncoder->encode($href)
105+
];
106+
if ($storeView->getCode() !== $store) {
107+
$query['___from_store'] = $storeView->getCode();
108+
}
109+
110+
return $query;
111+
}
112+
}

app/code/Magento/Cms/etc/adminhtml/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<argument name="frontendUrlBuilder" xsi:type="object">Magento\Framework\Url</argument>
1313
</arguments>
1414
</type>
15+
<type name="Magento\Cms\ViewModel\Page\Grid\UrlBuilder">
16+
<arguments>
17+
<argument name="frontendUrlBuilder" xsi:type="object">Magento\Framework\Url</argument>
18+
</arguments>
19+
</type>
1520
<type name="Magento\Cms\Model\Wysiwyg\CompositeConfigProvider">
1621
<arguments>
1722
<argument name="variablePluginConfigProvider" xsi:type="array">

0 commit comments

Comments
 (0)