Skip to content

Commit

Permalink
[BUGFIX] Streamline SoftReferenceIndex references
Browse files Browse the repository at this point in the history
This patch streamlines the return values for softref type typoscript and typoscript_tag. Furthermore tests for the API method findRef() are added to ensure same return results.

Furthermore  a non-reachable part in findRef_typolink_tag is removed. As the incoming content is split by <a> tags, the <LINK> tag condition within this function will be never fulfilled.

Resolves: #88207
Related: #87652
Releases: master, 9.5
Change-Id: Ifca40c5d0e049c5b5d92a507a9d5ec0249e9953e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62196
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
  • Loading branch information
IchHabRecht authored and georgringer committed Nov 6, 2019
1 parent 6404d04 commit 75aa958
Show file tree
Hide file tree
Showing 2 changed files with 385 additions and 162 deletions.
40 changes: 32 additions & 8 deletions typo3/sysext/core/Classes/Database/SoftReferenceIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,28 @@ public function findRef_typolink_tag($content)
'tokenID' => $token,
'tokenValue' => $linkDetails['url']
];
} elseif ($linkDetails['type'] === LinkService::TYPE_EMAIL) {
$token = $this->makeTokenID($key);
$elements[$key]['matchString'] = $linkTags[$key];
$linkTags[$key] = str_replace($matches[1], '{softref:' . $token . '}', $linkTags[$key]);
$elements[$key]['subst'] = [
'type' => 'string',
'tokenID' => $token,
'tokenValue' => $linkDetails['email']
];
} elseif ($linkDetails['type'] === LinkService::TYPE_TELEPHONE) {
$token = $this->makeTokenID($key);
$elements[$key]['matchString'] = $linkTags[$key];
$linkTags[$key] = str_replace($matches[1], '{softref:' . $token . '}', $linkTags[$key]);
$elements[$key]['subst'] = [
'type' => 'string',
'tokenID' => $token,
'tokenValue' => $linkDetails['telephone']
];
}
} catch (\Exception $e) {
// skip invalid links
}
} else {
// keep the legacy code for now
$typolinkValue = preg_replace('/<LINK[[:space:]]+/i', '', substr($foundValue, 0, -1));
$tLP = $this->getTypoLinkParts($typolinkValue);
$linkTags[$key] = '<LINK ' . $this->setTypoLinkPartsElement($tLP, $elements, $typolinkValue, $key) . '>';
}
}
}
Expand Down Expand Up @@ -477,10 +490,20 @@ public function setTypoLinkPartsElement($tLP, &$elements, $content, $idx)
// Output content will be the token instead:
$content = '{softref:' . $tokenID . '}';
break;
case LinkService::TYPE_TELEPHONE:
// phone number can be substituted manually:
$elements[$tokenID . ':' . $idx]['subst'] = [
'type' => 'string',
'tokenID' => $tokenID,
'tokenValue' => $tLP['telephone']
];
// Output content will be the token instead:
$content = '{softref:' . $tokenID . '}';
break;
case LinkService::TYPE_URL:
// URLs can be substituted manually
$elements[$tokenID . ':' . $idx]['subst'] = [
'type' => 'string',
'type' => 'external',
'tokenID' => $tokenID,
'tokenValue' => $tLP['url']
];
Expand All @@ -489,6 +512,7 @@ public function setTypoLinkPartsElement($tLP, &$elements, $content, $idx)
break;
case LinkService::TYPE_FOLDER:
// This is a link to a folder...
unset($elements[$tokenID . ':' . $idx]);
return $content;
case LinkService::TYPE_FILE:
// Process files referenced by their FAL uid
Expand Down Expand Up @@ -537,11 +561,11 @@ public function setTypoLinkPartsElement($tLP, &$elements, $content, $idx)
];
}
// Add type if applicable
if ((string)$tLP['pagetype'] !== '') {
if ((string)($tLP['pagetype'] ?? '') !== '') {
$content .= ',' . $tLP['pagetype'];
}
// Add anchor if applicable
if ((string)$tLP['anchor'] !== '') {
if ((string)($tLP['anchor'] ?? '') !== '') {
// Anchor is assumed to point to a content elements:
if (MathUtility::canBeInterpretedAsInteger($tLP['anchor'])) {
// Initialize a new entry because we have a new relation:
Expand Down
Loading

0 comments on commit 75aa958

Please sign in to comment.