diff --git a/classes/question_ui_renderer.php b/classes/question_ui_renderer.php index 45feec1..81c20a5 100644 --- a/classes/question_ui_renderer.php +++ b/classes/question_ui_renderer.php @@ -154,7 +154,6 @@ private function hide_unwanted_feedback(): void { private function shuffle_contents(): void { /** @var DOMElement $element */ foreach (iterator_to_array($this->xpath->query('//*[@qpy:shuffle-contents]')) as $element) { - $element->removeAttributeNS(constants::NAMESPACE_QPY, 'shuffle-contents'); $newelement = $element->cloneNode(); // We want to shuffle elements while leaving other nodes (such as text, spacing) where they are. @@ -181,6 +180,7 @@ private function shuffle_contents(): void { } } + $newelement->removeAttributeNS(constants::NAMESPACE_QPY, 'shuffle-contents'); $element->parentNode->replaceChild($newelement, $element); } } @@ -197,7 +197,7 @@ private function replace_shuffled_indices(DOMNode $element, int $index): void { foreach (iterator_to_array($this->xpath->query('.//qpy:shuffled-index', $element)) as $indexelement) { // phpcs:ignore Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterSecond for ( - $ancestor = $indexelement->parentNode; $ancestor !== null && $ancestor !== $indexelement; + $ancestor = $indexelement->parentNode; $ancestor !== null && $ancestor !== $element; $ancestor = $ancestor->parentNode ) { assert($ancestor instanceof DOMElement);