diff --git a/lib/FieldType/XmlText/Converter/RichText.php b/lib/FieldType/XmlText/Converter/RichText.php index db985104..8cf437cf 100644 --- a/lib/FieldType/XmlText/Converter/RichText.php +++ b/lib/FieldType/XmlText/Converter/RichText.php @@ -347,13 +347,15 @@ protected function checkEmptyEmbedTags(DOMDocument $inputDocument, $contentField } /** + * We need to lookup object_id/node_id for links which refers to object_remote_id or node_object_id. + * * Before calling this function, make sure you are logged in as admin, or at least have access to all the objects * being linked to in the $document. * @param DOMDocument $document * @param $contentFieldId */ - protected function checkLinkTags(DOMDocument $document, $contentFieldId) + protected function fixLinksWithRemoteIds(DOMDocument $document, $contentFieldId) { $xpath = new DOMXPath($document); @@ -394,6 +396,34 @@ protected function checkLinkTags(DOMDocument $document, $contentFieldId) } } + /** + * ezxmltext may contain link elements below another link element. This method flattens such structure. + * + * @param DOMDocument $document + * @param $contentFieldId + */ + 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->logger->warning("Found nested links. Flatten links where contentobject_attribute.id=$contentFieldId"); + } + } + /** * Before calling this function, make sure you are logged in as admin, or at least have access to all the objects * being embedded and linked to in the $inputDocument. @@ -409,7 +439,8 @@ public function convert(DOMDocument $inputDocument, $checkDuplicateIds = false, { $this->removeComments($inputDocument); $this->checkEmptyEmbedTags($inputDocument, $contentFieldId); - $this->checkLinkTags($inputDocument, $contentFieldId); + $this->fixLinksWithRemoteIds($inputDocument, $contentFieldId); + $this->flattenLinksInLinks($inputDocument, $contentFieldId); try { $convertedDocument = $this->getConverter()->convert($inputDocument); diff --git a/tests/lib/FieldType/Converter/_fixtures/richtext/input/047-link_in_link.xml b/tests/lib/FieldType/Converter/_fixtures/richtext/input/047-link_in_link.xml new file mode 100644 index 00000000..553553f6 --- /dev/null +++ b/tests/lib/FieldType/Converter/_fixtures/richtext/input/047-link_in_link.xml @@ -0,0 +1,11 @@ + +
+ paragraph text and ( + + some link text + ), after link. + +
diff --git a/tests/lib/FieldType/Converter/_fixtures/richtext/log/047-link_in_link.log b/tests/lib/FieldType/Converter/_fixtures/richtext/log/047-link_in_link.log new file mode 100644 index 00000000..9b489251 --- /dev/null +++ b/tests/lib/FieldType/Converter/_fixtures/richtext/log/047-link_in_link.log @@ -0,0 +1 @@ +warning:Found nested links. Flatten links where contentobject_attribute.id= diff --git a/tests/lib/FieldType/Converter/_fixtures/richtext/output/047-link_in_link.xml b/tests/lib/FieldType/Converter/_fixtures/richtext/output/047-link_in_link.xml new file mode 100644 index 00000000..88d158c7 --- /dev/null +++ b/tests/lib/FieldType/Converter/_fixtures/richtext/output/047-link_in_link.xml @@ -0,0 +1,10 @@ + +
+ paragraph text and ( + some link text), after link. + +