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:----AxoCCpgOo3JP4D2qurT3G9B3H/7I0TLNXHylN5Y+WbTflpWGc0kSzaQnmuNgsT4hwzQaVcAi7Sdo+0f/9s9rRsvoGvzWFb4cd5hLcxmeoX/5ibmf8vliX6p7cevzH01c6R7mUDir6BNCDLp5b8/hqp3a9XFxR3EwBwUC3zO1t2oAE092PB19dscOF/HmraljsqxE3fvZ6rKvKLRBfoc4Zd9OOZuqgLKFuXUfmkf1ZIvx0zMx4hlC8e01ChHCbxu+HdKpwLxluZOxqGRTi1WiS2AMWvwOnOjoXYamPgqEgjrtIAVvmw8tbgyRgk+d41Ym6jkIfU2xpLIXdrREve+LKjNIasdQhu68BgqLm1xAfYh/N89i2GosqvucfdWZhW726ruvDc52941a2LBXPW1XEcPu32XQ+t2Sbnpg53rIWvyuhxAPb6UblKhSwOvcENHKnmaQf2W2KPfwSnP2BEWflLAiiRqB81yBU/iHqR2nEdW6vYSDBpvoAILdpEkbCa8vqxljolzBpnIkHzxwX/yT+49u689f6GgmINbeuyVI0Kv9pbU2R4tqFYaLOlvurWTZD6nK+mXz9CGH0Y9KPnByUIx5inNT2mYs7cgebq+jV6MWwvv3am4MzNv2aV98WBq3Gbi4O0CvyDoad+7SP2ZHTzjWB1P175EnEhW3z+TevrI=----ATTACHMENT:----OTEwNDIzMzc5NTQ5NTIyNCA0MTI5NjQxNTc5OTc0NTIzIDMwNzk2MzU3OTY0Mzg2ODk=