1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* EventMapper. |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
declare(strict_types=1); |
7
|
|
|
|
8
|
|
|
namespace HDNET\Calendarize\Routing\Aspect; |
9
|
|
|
|
10
|
|
|
use HDNET\Calendarize\Service\Url\Typo3Route; |
11
|
|
|
use TYPO3\CMS\Core\Context\Context; |
12
|
|
|
use TYPO3\CMS\Core\Context\LanguageAspectFactory; |
13
|
|
|
use TYPO3\CMS\Core\Routing\Aspect\PersistedMappableAspectInterface; |
14
|
|
|
use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface; |
15
|
|
|
use TYPO3\CMS\Core\Routing\RouteNotFoundException; |
16
|
|
|
use TYPO3\CMS\Core\Site\SiteLanguageAwareInterface; |
17
|
|
|
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait; |
18
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* EventMapper. |
22
|
|
|
* |
23
|
|
|
* @deprecated |
24
|
|
|
*/ |
25
|
|
|
class EventMapper implements PersistedMappableAspectInterface, StaticMappableAspectInterface, SiteLanguageAwareInterface |
26
|
|
|
{ |
27
|
|
|
use SiteLanguageAwareTrait; |
28
|
|
|
|
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
@trigger_error( |
|
|
|
|
32
|
|
|
'EventMapper will be removed. Use the slug field with PersistedAliasMapper instead.', |
33
|
|
|
\E_USER_DEPRECATED |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $value |
39
|
|
|
* |
40
|
|
|
* @return string|null |
41
|
|
|
*/ |
42
|
|
|
public function generate(string $value): ?string |
43
|
|
|
{ |
44
|
|
|
$route = GeneralUtility::makeInstance(Typo3Route::class); |
45
|
|
|
$speaking = $route->convert(['generate' => $value], null); |
46
|
|
|
|
47
|
|
|
return $speaking; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $value |
52
|
|
|
* |
53
|
|
|
* @throws \Exception |
54
|
|
|
* |
55
|
|
|
* @return string|null |
56
|
|
|
*/ |
57
|
|
|
public function resolve(string $value): ?string |
58
|
|
|
{ |
59
|
|
|
// Set the language in the context, so that the index repository fetches |
60
|
|
|
// the translated record (is set in Typo3QuerySettings->initializeObject(), |
61
|
|
|
// which is used by findByUid). |
62
|
|
|
// This is only required, when a existing url is resolved, since the |
63
|
|
|
// value is checked for correctness with $this->generate. |
64
|
|
|
// Alternative: Use overlay function of the pageRepository, similar to PersistedPatternMapper |
65
|
|
|
// @TODO: Warning: This may have unexpected site effects! |
66
|
|
|
$context = GeneralUtility::makeInstance(Context::class); |
67
|
|
|
$context->setAspect( |
68
|
|
|
'language', |
69
|
|
|
LanguageAspectFactory::createFromSiteLanguage($this->siteLanguage) |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$route = GeneralUtility::makeInstance(Typo3Route::class); |
73
|
|
|
$id = (string)$route->convert(['resolve' => $value], null); |
74
|
|
|
|
75
|
|
|
if ($this->generate($id) !== $value) { |
76
|
|
|
throw new RouteNotFoundException('Wrong realurl segment', 12378); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $id; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: