Skip to content

Commit 4c6bb85

Browse files
authored
[5.3] Fields batch copy category (joomla#44943)
1 parent 1d7650b commit 4c6bb85

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

administrator/components/com_fields/src/Model/FieldModel.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,16 @@ protected function batchCopy($value, $pks, $contexts)
11681168

11691169
foreach ($pks as $pk) {
11701170
if ($user->authorise('core.create', $component . '.fieldgroup.' . $value)) {
1171+
// Find all assigned categories to this field
1172+
$db = $this->getDatabase();
1173+
$query = $db->getQuery(true);
1174+
1175+
$query->select($db->quoteName('category_id'))
1176+
->from($db->quoteName('#__fields_categories'))
1177+
->where($db->quoteName('field_id') . ' = ' . (int) $pk);
1178+
1179+
$assignedCatIds = $db->setQuery($query)->loadColumn();
1180+
11711181
$table->reset();
11721182
$table->load($pk);
11731183

@@ -1194,6 +1204,17 @@ protected function batchCopy($value, $pks, $contexts)
11941204
// Get the new item ID
11951205
$newId = $table->id;
11961206

1207+
// Inset the assigned categories
1208+
if (!empty($assignedCatIds)) {
1209+
$tuple = new \stdClass();
1210+
$tuple->field_id = $newId;
1211+
1212+
foreach ($assignedCatIds as $catId) {
1213+
$tuple->category_id = $catId;
1214+
$db->insertObject('#__fields_categories', $tuple);
1215+
}
1216+
}
1217+
11971218
// Add the new ID to the array
11981219
$newIds[$pk] = $newId;
11991220
} else {

0 commit comments

Comments
 (0)