@@ -59,7 +59,7 @@ public function processDatamap_afterDatabaseOperations($command, $table, $id, $f
59
59
(int )$ mostRecentCopyOfParentRecord ['uid ' ],
60
60
$ localColumnPosition
61
61
);
62
- $ reference ->updateDB ($ table , $ newRecordUid , ['colPos ' => $ newColumnPosition ]);
62
+ $ reference ->updateDB ($ table , $ newRecordUid , ['colPos ' => $ newColumnPosition, ' pid ' => $ mostRecentCopyOfParentRecord [ ' pid ' ] ]);
63
63
}
64
64
}
65
65
}
@@ -162,7 +162,7 @@ public function processCmdmap_postProcess(&$command, $table, $id, &$relativeTo,
162
162
list ($ originalRecord , $ recordsToCopy ) = $ this ->getParentAndRecordsNestedInGrid (
163
163
$ table ,
164
164
(int )$ id ,
165
- 'uid, colPos '
165
+ 'uid, pid, colPos '
166
166
);
167
167
168
168
if (empty ($ recordsToCopy )) {
@@ -171,23 +171,30 @@ public function processCmdmap_postProcess(&$command, $table, $id, &$relativeTo,
171
171
172
172
$ languageField = $ GLOBALS ['TCA ' ][$ table ]['ctrl ' ]['languageField ' ];
173
173
174
+ if ($ relativeTo > 0 ) {
175
+ $ destinationPid = $ relativeTo ;
176
+ } else {
177
+ $ relativeRecord = $ this ->getSingleRecordWithoutRestrictions ($ table , abs ($ relativeTo ), 'pid ' );
178
+ $ destinationPid = $ relativeRecord ['pid ' ] ?? $ relativeTo ;
179
+ }
174
180
175
181
foreach ($ recordsToCopy as $ recordToCopy ) {
176
182
$ languageUid = (int ) ($ reference ->cmdmap [$ table ][$ id ][$ command ]['update ' ][$ languageField ] ?? $ recordToCopy [$ languageField ]);
177
183
$ newChildUid = $ reference ->copyRecord (
178
184
$ table ,
179
185
$ recordToCopy ['uid ' ],
180
- $ originalRecord [ ' pid ' ] ,
186
+ $ destinationPid ,
181
187
true ,
182
188
[
183
189
$ languageField => $ languageUid ,
184
190
'colPos ' => ColumnNumberUtility::calculateColumnNumberForParentAndColumn (
185
191
$ reference ->copyMappingArray [$ table ][$ id ],
186
192
ColumnNumberUtility::calculateLocalColumnNumber ($ recordToCopy ['colPos ' ])
187
- )
193
+ ),
194
+ 'pid ' => $ destinationPid
188
195
]
189
196
);
190
- $ this ->recursivelyCopyChildRecords ($ table , $ recordToCopy ['uid ' ], $ newChildUid , $ languageUid , $ reference );
197
+ $ this ->recursivelyCopyChildRecords ($ table , $ recordToCopy ['uid ' ], $ newChildUid , $ destinationPid , $ languageUid , $ reference );
191
198
}
192
199
}
193
200
@@ -199,7 +206,7 @@ public function clearCacheCommand($command)
199
206
{
200
207
}
201
208
202
- protected function recursivelyCopyChildRecords (string $ table , int $ parentUid , int $ newParentUid , int $ languageUid , DataHandler $ dataHandler )
209
+ protected function recursivelyCopyChildRecords (string $ table , int $ parentUid , int $ newParentUid , int $ pageUid , int $ languageUid , DataHandler $ dataHandler )
203
210
{
204
211
list ($ originalRecord , $ recordsToCopy ) = $ this ->getParentAndRecordsNestedInGrid (
205
212
$ table ,
@@ -217,17 +224,18 @@ protected function recursivelyCopyChildRecords(string $table, int $parentUid, in
217
224
$ newChildUid = $ dataHandler ->copyRecord (
218
225
$ table ,
219
226
$ recordToCopy ['uid ' ],
220
- $ originalRecord [ ' pid ' ] ,
227
+ $ pageUid ,
221
228
true ,
222
229
[
223
230
$ languageField => $ languageUid ,
224
231
'colPos ' => ColumnNumberUtility::calculateColumnNumberForParentAndColumn (
225
232
$ newParentUid ,
226
233
ColumnNumberUtility::calculateLocalColumnNumber ($ recordToCopy ['colPos ' ])
227
- )
234
+ ),
235
+ 'pid ' => $ pageUid
228
236
]
229
237
);
230
- $ this ->recursivelyCopyChildRecords ($ table , $ recordToCopy ['uid ' ], $ newChildUid , $ languageUid , $ dataHandler );
238
+ $ this ->recursivelyCopyChildRecords ($ table , $ recordToCopy ['uid ' ], $ newChildUid , $ pageUid , $ languageUid , $ dataHandler );
231
239
}
232
240
}
233
241
0 commit comments