Skip to content

Commit 967740b

Browse files
committed
Force URL generation for missing entities.
If a target entity is missing, an aspect would not generate a mapping for a parameter and would generate an ugly URL containing tx_vierwdXXX parameters.
1 parent a4a7170 commit 967740b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Classes/Routing/Aspect/AutomaticSlugPatternMapper.php

+22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
* routeFieldPattern: '^(?P<title>.+)-(?P<uid>\d+)$'
3333
* routeFieldResult: '{title}-{uid}'
3434
* matchFields: ['uid']
35+
* checkExistence: false
36+
*
37+
* When generating a URL, a warning is generated if the target entity does not exist.
38+
* You can disable this warning using checkExistence: false
3539
*/
3640
class AutomaticSlugPatternMapper extends PersistedPatternMapper {
3741

@@ -45,6 +49,24 @@ public function __construct(array $settings) {
4549
}
4650
}
4751

52+
/**
53+
* {@inheritdoc}
54+
*/
55+
public function generate(string $value): ?string {
56+
$generatedValue = parent::generate($value);
57+
if ($generatedValue !== null) {
58+
return $generatedValue;
59+
}
60+
61+
if ($this->settings['checkExistence'] ?? true) {
62+
trigger_error('URL Generation failed for ' . $this->settings['tableName'] . ': ' . $value, E_USER_WARNING);
63+
}
64+
// https://forge.typo3.org/issues/103844
65+
// Since TYPO3 v11.5.37 only URLs to valid entites are generated.
66+
// In some cases we want to allow invalid URLs as well
67+
return $value;
68+
}
69+
4870
protected function createRouteResult(?array $result): ?string {
4971
if ($result === null) {
5072
return $result;

0 commit comments

Comments
 (0)