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:----LhOF2iBVp4dXKO1625hbbX6aUwQaYkACotBKOqFc9oJs+IAwgilllMiwfJsoaQff/cg3D39l2X/NC5Q0//pQXahzF0WUdiEPMkCuejlkZzTFaf9xjaX6zhZ04f0N5MsC804WV+DpfmaHpEntkRwU1HtTlca/P8OVogBtgG+jOppMVzZL6UN/JvVsjQe6YMCKJSA/1lNI7VFQtS/TmCBrHDr36n7zYPJn9Zmq82TBTkSKcfaLdAdFoiGRKBBY9dqYTEq/Kp4/FCuyeVS0kh2IF5aHNqbPf9icob9mu80ZkJ1rA6hg/3RZt0Z2Jiry8rPIy0zSu+thYH/GSkPS3JYjCvTMs6reRVUNOnYKtajpn1NPerX3Fw/N7by1z0Vpylif5zBPWKZ7CP737dUYcp0+eLnbWi2AKOUTdczLfSI8Gubq4phUdL48sTbc5o4v7uKNHTIbmw8QgY80zlon+OC0jMZULgwj12ICN5zwt6+RwSbnR9aHwE7u48F8QNzH2JXG+Z0fd9jd97J0UnI6LK67zDcZ92qFmUgSeVtmu8mD93PkrjI9XM+YI2pKSxPAvwL8FmyHX9TAJiecB69tQ2F16DmkA5WgPC0pQBuiUwhBTilRwSgKPhCn7x09Q2JlEjDbdQmP2x9o6ImiIC3Rjbri8xQxiVKJKFnGQjoOSWNlFvQ=----ATTACHMENT:----NDc0NTgyMzEzNDQ3NTc1MSAzMDE1NjM2ODMxNTIxMjEwIDE5NDc0MTk2ODQxOTc5Ng==