featdd / dpn_glossary

Glossary extension for TYPO3
http://typo3.org/extensions/repository/view/dpn_glossary
GNU General Public License v2.0
20 stars 29 forks source link

More than one synonym not parsed #213

Closed kayATcu closed 6 months ago

kayATcu commented 6 months ago

Hi,

we have typo3 version 12 and use this extension in the newest version.

But if i have more than one "synonyms", it will underline only the first synonym in frontend and not the others. 2024-02-29_15-33

Best regards, Kay

featdd commented 6 months ago

Hi @kayATcu,

have you set a max replacement limit?

Greetings Daniel

kayATcu commented 6 months ago

@featdd no. Everything is default. grafik 2024-02-29_16-18 2024-02-29_16-18_1

kayATcu commented 6 months ago

@featdd i think i found the problem and a solution....

--- vendor/featdd/dpn-glossary/Classes/Service/ParserService.php    2024-02-18 21:15:02.000000000 +0100
+++ patches/ParserService-new.php   2024-03-01 11:10:00.536245476 +0100
@@ -405,8 +405,9 @@

             if ($isParseSynonyms) {
                 $synonymTermObject = clone $termObject;
+                $allSynonyms = $termObject->getSynonyms()->toArray();
                 /** @var \Featdd\DpnGlossary\Domain\Model\Synonym $synonym */
-                foreach ($termObject->getSynonyms() as $synonym) {
+                foreach ($allSynonyms as $synonym) {
                     $synonymTermObject->{
                     ($this->settings['useTermForSynonymParsingDataWrap'] ?? false)
                         ? 'setParsingName'

Greetings, Kay

featdd commented 6 months ago

Hi @kayATcu,

I couldn't believe my eyes first when I reproduced this and struggled to find an explanation, this is really a fine piece of an edge case. 😅

The issue was that I build a nested iteration over the synonym ObjectStorage, because inside the iteration the parser calls the "__toArray()" function of the term, wich also iterates over the ObjectStorage. This is resulting in an array reset inside the ObjectStorage's internal array, messing up the overlaying iteration and so on...

Anyway here's the fix: 86a5767db2d209d4a64868a31d3d4f9ae5356936

I will also prepare an update for the TER.

Greetings Daniel