9
9
use Magento \Cms \Api \Data ;
10
10
use Magento \Cms \Api \PageRepositoryInterface ;
11
11
use Magento \Cms \Model \Page \IdentityMap ;
12
+ use Magento \Cms \Model \ResourceModel \Page as ResourcePage ;
13
+ use Magento \Cms \Model \ResourceModel \Page \CollectionFactory as PageCollectionFactory ;
12
14
use Magento \Framework \Api \DataObjectHelper ;
13
15
use Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface ;
14
16
use Magento \Framework \App \ObjectManager ;
17
+ use Magento \Framework \EntityManager \HydratorInterface ;
15
18
use Magento \Framework \Exception \CouldNotDeleteException ;
16
19
use Magento \Framework \Exception \CouldNotSaveException ;
17
20
use Magento \Framework \Exception \NoSuchEntityException ;
18
21
use Magento \Framework \Reflection \DataObjectProcessor ;
19
- use Magento \Cms \Model \ResourceModel \Page as ResourcePage ;
20
- use Magento \Cms \Model \ResourceModel \Page \CollectionFactory as PageCollectionFactory ;
21
22
use Magento \Store \Model \StoreManagerInterface ;
22
23
23
24
/**
24
- * Class PageRepository
25
+ * @inheritdoc
26
+ *
25
27
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26
28
*/
27
29
class PageRepository implements PageRepositoryInterface
@@ -76,6 +78,11 @@ class PageRepository implements PageRepositoryInterface
76
78
*/
77
79
private $ identityMap ;
78
80
81
+ /**
82
+ * @var HydratorInterface
83
+ */
84
+ private $ hydrator ;
85
+
79
86
/**
80
87
* @param ResourcePage $resource
81
88
* @param PageFactory $pageFactory
@@ -87,6 +94,7 @@ class PageRepository implements PageRepositoryInterface
87
94
* @param StoreManagerInterface $storeManager
88
95
* @param CollectionProcessorInterface $collectionProcessor
89
96
* @param IdentityMap|null $identityMap
97
+ * @param HydratorInterface|null $hydrator
90
98
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
91
99
*/
92
100
public function __construct (
@@ -99,7 +107,8 @@ public function __construct(
99
107
DataObjectProcessor $ dataObjectProcessor ,
100
108
StoreManagerInterface $ storeManager ,
101
109
CollectionProcessorInterface $ collectionProcessor = null ,
102
- ?IdentityMap $ identityMap = null
110
+ ?IdentityMap $ identityMap = null ,
111
+ ?HydratorInterface $ hydrator = null
103
112
) {
104
113
$ this ->resource = $ resource ;
105
114
$ this ->pageFactory = $ pageFactory ;
@@ -111,6 +120,7 @@ public function __construct(
111
120
$ this ->storeManager = $ storeManager ;
112
121
$ this ->collectionProcessor = $ collectionProcessor ?: $ this ->getCollectionProcessor ();
113
122
$ this ->identityMap = $ identityMap ?? ObjectManager::getInstance ()->get (IdentityMap::class);
123
+ $ this ->hydrator = $ hydrator ?: ObjectManager::getInstance ()->get (HydratorInterface::class);
114
124
}
115
125
116
126
/**
@@ -150,8 +160,13 @@ public function save(\Magento\Cms\Api\Data\PageInterface $page)
150
160
$ storeId = $ this ->storeManager ->getStore ()->getId ();
151
161
$ page ->setStoreId ($ storeId );
152
162
}
163
+ $ pageId = $ page ->getId ();
164
+
153
165
try {
154
166
$ this ->validateLayoutUpdate ($ page );
167
+ if ($ pageId ) {
168
+ $ page = $ this ->hydrator ->hydrate ($ this ->getById ($ pageId ), $ this ->hydrator ->extract ($ page ));
169
+ }
155
170
$ this ->resource ->save ($ page );
156
171
$ this ->identityMap ->add ($ page );
157
172
} catch (\Exception $ exception ) {
@@ -248,6 +263,7 @@ private function getCollectionProcessor()
248
263
{
249
264
if (!$ this ->collectionProcessor ) {
250
265
$ this ->collectionProcessor = \Magento \Framework \App \ObjectManager::getInstance ()->get (
266
+ // phpstan:ignore "Class Magento\Cms\Model\Api\SearchCriteria\PageCollectionProcessor not found."
251
267
\Magento \Cms \Model \Api \SearchCriteria \PageCollectionProcessor::class
252
268
);
253
269
}
0 commit comments