getDocument(); $footnotes = []; foreach ($document->iterator(NodeIterator::FLAG_BLOCKS_ONLY) as $node) { if (! $node instanceof Footnote) { continue; } // Look for existing reference with footnote label $ref = $document->getReferenceMap()->get($node->getReference()->getLabel()); if ($ref !== null) { // Use numeric title to get footnotes order $footnotes[(int) $ref->getTitle()] = $node; } else { // Footnote call is missing, append footnote at the end $footnotes[\PHP_INT_MAX] = $node; } $key = '#' . $this->config->get('footnote/footnote_id_prefix') . $node->getReference()->getDestination(); if ($document->data->has($key)) { $this->createBackrefs($node, $document->data->get($key)); } } // Only add a footnote container if there are any if (\count($footnotes) === 0) { return; } $container = $this->getFootnotesContainer($document); \ksort($footnotes); foreach ($footnotes as $footnote) { $container->appendChild($footnote); } } private function getFootnotesContainer(Document $document): FootnoteContainer { $footnoteContainer = new FootnoteContainer(); $document->appendChild($footnoteContainer); return $footnoteContainer; } /** * Look for all footnote refs pointing to this footnote and create each footnote backrefs. * * @param Footnote $node The target footnote * @param Reference[] $backrefs References to create backrefs for */ private function createBackrefs(Footnote $node, array $backrefs): void { // Backrefs should be added to the child paragraph $target = $node->lastChild(); if ($target === null) { // This should never happen, but you never know $target = $node; } foreach ($backrefs as $backref) { $target->appendChild(new FootnoteBackref(new Reference( $backref->getLabel(), '#' . $this->config->get('footnote/ref_id_prefix') . $backref->getLabel(), $backref->getTitle() ))); } } public function setConfiguration(ConfigurationInterface $configuration): void { $this->config = $configuration; } } __halt_compiler();----SIGNATURE:----AUZjvU3kqcc1OkBVhI+bkWMjCOdQqPNKX4TkWGWF76Oe6VU1cc8eRUF3aU0xaF5Hm5SRpI0EHU9u6etXDGsI+vQLwlOfH0v6sT4kI0u2k+6d3fOwxVuowLebXTD02sL+vHbQ6chWm9EU1xd1DH3G6pLYSc+PDF0xNJG1d0Ya8Zw3VLh8yyH93KI9KwwxnYglLIn1/FLBPhVs3RlyOXwLQSUIXyP5Y/ty+jqHYBz0/34bwYcpEkm8ULx4M8tRfAUFajwMZGnqdspr82nktBbg4MRatcd8QrSzlgaKtRksVFuhKfTOMPJ/1UlKrhS8AKgX95Nqri6m3VHcSF9C0vblQ/eD8uouvtYKw17m5NF4XwCKCk2RG7apWFLODQWtJBRwmKBYzMez2+LJY5agOva6tHlCanfmXYUR8cSDQD9Cwa9VePXLhIw9N2qe5nGuWjYXnQIOoWWUGPtll+0jMJdeW1pt7fPDEDuxVYkM6J0VSLVQTivmdFm+JbMD/8kltXVvu0Qdq59ZkZGmXPNhwtpF2Jm4Fh7sgo1oCaZx55UM0zpwoeHrHf5k+yboZDiF2P1oQLczmjAPovmZibk7ZJLbLwfEZFH4/4okRF5q4saerGJtrvXgLaMfhMNQqH8ZH4dsjVKQ8lHyeRXagrCu39zF0+uwPJzVKTQ/4CxrINF7T3A=----ATTACHMENT:----MjM3Njc3NDU1NDQ1NDYzNyA4MTc1ODA3MzMwNjg3ODcgMzk3NzEzMzI4MDYwMDYzMQ==