protected function flattenLinksInLinks(DOMDocument $document, $contentFieldId)
    {
        $xpath = new DOMXPath($document);

        // Get all link elements which are child of a link
        $xpathExpression = '//link[parent::link]';

        $links = $xpath->query($xpathExpression);

        foreach ($links as $link) {
            // Move link to parent
            $targetElement = $link->parentNode->parentNode;
            $parentLink = $link->parentNode;
            $targetElement->insertBefore($link, $parentLink);

            // We want parent link to be listed first.
            $targetElement->insertBefore($parentLink, $link);

            $this->log(LogLevel::NOTICE, "Found nested links. Flatten links where contentobject_attribute.id=$contentFieldId");
        }
    }