Commit 739a3099 authored by Daniel Siepmann's avatar Daniel Siepmann Committed by Thomas Löffler

Check all possible version numbers for manual url

An extension can have different kinds of version numbers. All of them
need to be checked. Before only one version variant was checked. But the
version can be prefixed with `v` or can consists of only two version
parts.
parent ab3cf4e5
......@@ -64,10 +64,14 @@ class DocumentationService implements \TYPO3\CMS\Core\SingletonInterface
$documentationLink = '';
$oldManualsInformation = json_decode(@file_get_contents(PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'oldmanuals.json'), true);
if (isset($this->docsInformation[$extensionKey]['docs'][$versionString])) {
// link to extension to get the latest manual
$url = $this->docsInformation[$extensionKey]['docs'][$versionString]['url'];
} elseif (isset($oldManualsInformation[$extensionKey])) {
foreach ($this->getPossibleVersionStrings($versionString) as $possibleVersionString) {
if (isset($this->docsInformation[$extensionKey]['docs'][$possibleVersionString])) {
$url = $this->docsInformation[$extensionKey]['docs'][$possibleVersionString]['url'];
break;
}
}
if ($url === '' && isset($oldManualsInformation[$extensionKey])) {
$baseUrl = 'https://docs.typo3.org/typo3cms/extensions/';
$url = $baseUrl . $extensionKey . '/';
}
......@@ -78,4 +82,27 @@ class DocumentationService implements \TYPO3\CMS\Core\SingletonInterface
return $returnUrlOnly ? $url : $documentationLink;
}
private function getPossibleVersionStrings(string $defaultVersion): array
{
$possibleVersionStrings = [
$defaultVersion,
// just 2 points without v
];
$versionParts = explode('.', $string);
if (count($versionParts) === 3) {
$possibleVersionStrings[] = implode(array_slice($versionParts, 0, 2), '.');
}
if (substr($defaultVersion, 0, 1) === 'v') {
$possibleVersionStrings[] = ltrim($defaultVersion, 'v');
}
if (count($versionParts) === 3 && substr($defaultVersion, 0, 1) === 'v') {
$possibleVersionStrings[] = ltrim(implode(array_slice($versionParts, 0, 2), '.'), 'v');
}
return $possibleVersionStrings;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment