diff --git a/core/includes/form.inc b/core/includes/form.inc index 32309a1882..1db96220ad 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -773,9 +773,6 @@ function batch_set($batch_definition) { } $batch_set['appended_after_index'] = $append_after_index; - $new_set_index = count($batch['sets']); - $new_sets = []; - // Iterate by reference over the existing batch sets and assign them by // reference in the new batch sets array in order not to break a retrieved // reference to the current set. Among other places a reference to the @@ -787,9 +784,11 @@ function batch_set($batch_definition) { // using not a new, but an existing and already used index for the new // batch set. // @see _batch_populate_queue(). + $new_sets = []; foreach ($batch['sets'] as $index => &$set) { $new_sets[$index] = &$set; if ($index == $append_after_index) { + $new_set_index = count($batch['sets']); $new_sets[$new_set_index] = $batch_set; } }