@@ -235,6 +235,7 @@ function format_multitopic_reorder_sections(array $sectionsextra, $origins, \std
235235 $ prevextra = null ;
236236 $ found = false ;
237237 $ appendextraarray = [];
238+ $ newposition = 0 ;
238239 foreach ($ sectionsextra as $ id => $ sectionextra ) {
239240 if ($ found ) {
240241 // Target position already found, extract remaining sections.
@@ -257,7 +258,8 @@ function format_multitopic_reorder_sections(array $sectionsextra, $origins, \std
257258 } else if (isset ($ parentextra )
258259 && ($ sectionextra ->levelsan < $ target ->level || $ sectionextra ->levelsan <= $ parentextra ->levelsan )
259260 || isset ($ prevextra ) && ($ sectionextra ->levelsan <= $ target ->level )
260- || isset ($ target ->nextupid ) && $ sectionextra ->id == $ target ->nextupid ) {
261+ || isset ($ target ->nextupid ) && ($ sectionextra ->id == $ target ->nextupid )
262+ || isset ($ target ->section ) && ($ newposition == $ target ->section )) {
261263 // Reached the last position in a specified parent in which the moved section would be a (direct) child,
262264 // or the appropriate position after a specified previous section,
263265 // or the position before a specified next section.
@@ -269,8 +271,11 @@ function format_multitopic_reorder_sections(array $sectionsextra, $origins, \std
269271 unset($ sectionsextra [$ id ]);
270272 $ found = true ;
271273 }
274+ $ newposition ++;
272275 }
273- if (isset ($ parentextra ) || isset ($ prevextra )) {
276+ if (isset ($ parentextra ) || isset ($ prevextra )
277+ || property_exists ($ target , 'nextupid ' ) && ($ target ->nextupid == null )
278+ || isset ($ target ->section ) && ($ newposition == $ target ->section )) {
274279 // If a specified parent or previous was found, but no position within the section list was appropriate,
275280 // the appropriate position must be the end of the section list.
276281 $ found = true ;
0 commit comments