15
15
use eZ \Publish \SPI \Persistence \Content \CreateStruct ;
16
16
use eZ \Publish \SPI \Persistence \Content \Field ;
17
17
use eZ \Publish \SPI \Persistence \Content \Handler as BaseContentHandler ;
18
+ use eZ \Publish \SPI \Persistence \Content \Language \Handler as LanguageHandler ;
18
19
use eZ \Publish \SPI \Persistence \Content \MetadataUpdateStruct ;
19
20
use eZ \Publish \SPI \Persistence \Content \Relation \CreateStruct as RelationCreateStruct ;
20
21
use eZ \Publish \SPI \Persistence \Content \Type \Handler as ContentTypeHandler ;
@@ -84,6 +85,11 @@ class Handler implements BaseContentHandler
84
85
*/
85
86
protected $ treeHandler ;
86
87
88
+ /**
89
+ * @var \eZ\Publish\SPI\Persistence\Content\Language\Handler
90
+ */
91
+ protected $ languageHandler ;
92
+
87
93
/** @var \Psr\Log\LoggerInterface */
88
94
private $ logger ;
89
95
@@ -109,6 +115,7 @@ public function __construct(
109
115
UrlAliasGateway $ urlAliasGateway ,
110
116
ContentTypeHandler $ contentTypeHandler ,
111
117
TreeHandler $ treeHandler ,
118
+ LanguageHandler $ languageHandler ,
112
119
LoggerInterface $ logger = null
113
120
) {
114
121
$ this ->contentGateway = $ contentGateway ;
@@ -119,6 +126,7 @@ public function __construct(
119
126
$ this ->urlAliasGateway = $ urlAliasGateway ;
120
127
$ this ->contentTypeHandler = $ contentTypeHandler ;
121
128
$ this ->treeHandler = $ treeHandler ;
129
+ $ this ->languageHandler = $ languageHandler ;
122
130
$ this ->logger = null !== $ logger ? $ logger : new NullLogger ();
123
131
}
124
132
@@ -255,6 +263,8 @@ public function publish($contentId, $versionNo, MetadataUpdateStruct $metaDataUp
255
263
* @param string|null $languageCode
256
264
*
257
265
* @return \eZ\Publish\SPI\Persistence\Content
266
+ *
267
+ * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
258
268
*/
259
269
public function createDraftFromVersion ($ contentId , $ srcVersion , $ userId , ?string $ languageCode = null )
260
270
{
@@ -275,6 +285,14 @@ public function createDraftFromVersion($contentId, $srcVersion, $userId, ?string
275
285
// Clone fields from previous version and append them to the new one
276
286
$ this ->fieldHandler ->createExistingFieldsInNewVersion ($ content );
277
287
288
+ // Persist virtual fields
289
+ $ contentType = $ this ->contentTypeHandler ->load ($ content ->versionInfo ->contentInfo ->contentTypeId );
290
+ $ this ->fieldHandler ->updateFields ($ content , new UpdateStruct ([
291
+ 'initialLanguageId ' => $ this ->languageHandler ->loadByLanguageCode (
292
+ $ content ->versionInfo ->initialLanguageCode
293
+ )->id ,
294
+ ]), $ contentType );
295
+
278
296
// Create relations for new version
279
297
$ relations = $ this ->contentGateway ->loadRelations ($ contentId , $ srcVersion );
280
298
foreach ($ relations as $ relation ) {
@@ -320,7 +338,9 @@ public function load($id, $version = null, array $translations = null)
320
338
$ this ->contentGateway ->loadVersionedNameData ([[
321
339
'id ' => $ id ,
322
340
'version ' => $ rows [0 ]['ezcontentobject_version_version ' ],
323
- ]])
341
+ ]]),
342
+ 'ezcontentobject_ ' ,
343
+ $ translations
324
344
);
325
345
$ content = $ contentObjects [0 ];
326
346
unset($ rows , $ contentObjects );
@@ -371,7 +391,9 @@ public function loadContentList(array $contentIds, array $translations = null):
371
391
try {
372
392
$ contentList = $ this ->mapper ->extractContentFromRows (
373
393
$ contentItemsRow ,
374
- $ contentItemNameData [$ contentId ]
394
+ $ contentItemNameData [$ contentId ],
395
+ 'ezcontentobject_ ' ,
396
+ $ translations
375
397
);
376
398
$ contentItems [$ contentId ] = $ contentList [0 ];
377
399
} catch (Exception $ e ) {
0 commit comments