Skip to content

Commit 665114e

Browse files
authored
[FEATURE] Allow to specify headline anchor explicitly (#32)
1 parent 4d33c06 commit 665114e

9 files changed

+31
-1
lines changed

config/typo3/01_viewhelpers_global.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
"sourcePrefix": "https://github.com/TYPO3/typo3/blob/main/typo3/sysext/fluid/Classes/ViewHelpers/",
1717
"editPrefix": "https://github.com/TYPO3/typo3/edit/main/typo3/sysext/fluid/Classes/ViewHelpers/"
1818
}
19+
},
20+
"headlineIdentifierPrefix": {
21+
"http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers": "typo3-fluid"
1922
}
2023
}

config/typo3/02_viewhelpers_core.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"sourcePrefix": "https://github.com/TYPO3/typo3/blob/main/typo3/sysext/core/Classes/ViewHelpers/",
99
"editPrefix": "https://github.com/TYPO3/typo3/edit/main/typo3/sysext/core/Classes/ViewHelpers/"
1010
}
11+
},
12+
"headlineIdentifierPrefix": {
13+
"http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers": "typo3-core"
1114
}
1215
}

config/typo3/03_viewhelpers_backend.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"sourcePrefix": "https://github.com/TYPO3/typo3/blob/main/typo3/sysext/backend/Classes/ViewHelpers/",
99
"editPrefix": "https://github.com/TYPO3/typo3/edit/main/typo3/sysext/backend/Classes/ViewHelpers/"
1010
}
11+
},
12+
"headlineIdentifierPrefix": {
13+
"http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers": "typo3-backend"
1114
}
1215
}

config/typo3/04_viewhelpers_form.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"sourcePrefix": "https://github.com/TYPO3/typo3/blob/main/typo3/sysext/form/Classes/ViewHelpers/",
99
"editPrefix": "https://github.com/TYPO3/typo3/edit/main/typo3/sysext/form/Classes/ViewHelpers/"
1010
}
11+
},
12+
"headlineIdentifierPrefix": {
13+
"http://typo3.org/ns/TYPO3/CMS/Form/ViewHelpers": "typo3-form"
1114
}
1215
}

src/Config.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
"editPrefix": { "type": "string" }
5252
}
5353
}
54+
},
55+
"headlineIdentifierPrefix": {
56+
"description": "Per-namespace configuration of prefixes for headline anchor names in the rendered documentation",
57+
"type": "object",
58+
"additionalProperties": {
59+
"type": "string"
60+
}
5461
}
5562
},
5663
"required": [

src/ConsoleRunner.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ private function renderViewHelperDocumentation(ViewHelperPackage $package, ViewH
184184
{
185185
$sourceEdit = $package->sourceEdit[$viewHelper->metadata->xmlNamespace] ?? null;
186186

187-
$headlineIdentifier = str_replace(['.', "'", '/', '\\'], '-', strtolower(sprintf('%s-%s', $viewHelper->namespaceWithoutSuffix, $viewHelper->nameWithoutSuffix)));
187+
$headlineIdentifierPrefix = $package->headlineIdentifierPrefix[$viewHelper->metadata->xmlNamespace]
188+
?? str_replace(['.', "'", '/', '\\'], '-', strtolower($viewHelper->namespaceWithoutSuffix));
189+
$headlineIdentifier = sprintf('%s-%s', $headlineIdentifierPrefix, str_replace(['.', "'", '/', '\\'], '-', strtolower($viewHelper->nameWithoutSuffix)));
188190

189191
$view = $this->createView($templateFile);
190192
$view->assignMultiple([
@@ -298,6 +300,7 @@ private function createPackageFromConfigFile(string $filePath): ViewHelperPackag
298300
...array_map(fn($path) => $this->preparePath($path, $configPath), (array)($config->templates ?? [])),
299301
],
300302
sourceEdit: isset($config->sourceEdit) ? (array)$config->sourceEdit : null,
303+
headlineIdentifierPrefix: isset($config->headlineIdentifierPrefix) ? (array)$config->headlineIdentifierPrefix : null,
301304
);
302305
}
303306

src/ViewHelperPackage.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ final class ViewHelperPackage
2525
* @param string[] $includesNamespaces
2626
* @param array<string, string> $templates
2727
* @param array<string, object> $sourceEdit
28+
* @param array<string, string> $headlineIdentifierPrefix
2829
*/
2930
public function __construct(
3031
public readonly string $name,
@@ -34,5 +35,6 @@ public function __construct(
3435
public readonly array $includesNamespaces,
3536
public readonly array $templates,
3637
public readonly ?array $sourceEdit,
38+
public readonly ?array $headlineIdentifierPrefix,
3739
) {}
3840
}

tests/Fixtures/SerializePackageResult.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@
4141
"editPrefix": "http://example.com/edit/",
4242
"sourcePrefix": "http://example.com/source/"
4343
}
44+
},
45+
"headlineIdentifierPrefix": {
46+
"http://typo3.org/ns/Vendor/MyPackage/ViewHelpers/": "vendor-mypackage"
4447
}
4548
}

tests/Functional/SerializePackageTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public function serializePackage(): void
5858
'sourcePrefix' => 'http://example.com/source/',
5959
],
6060
],
61+
[
62+
'http://typo3.org/ns/Vendor/MyPackage/ViewHelpers/' => 'vendor-mypackage',
63+
],
6164
);
6265
$package->uri = 'Global/Index';
6366
$package->viewHelpers = [$viewHelper];

0 commit comments

Comments
 (0)