Skip to content

Commit 256d3bf

Browse files
committed
Add support for synthetic apps to the rewrite test
1 parent 31042b3 commit 256d3bf

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

wcfsetup/install/files/acp/templates/__optionRewriteTest.tpl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
'wcf.acp.option.url_omit_index_php.test.status.success': '{jslang}wcf.acp.option.url_omit_index_php.test.status.success{/jslang}'
3232
});
3333
34-
const apps = new Map(Object.entries({
35-
{* this bypasses the route system to force rewritten urls *}
36-
{implode from=$rewriteTestApplications item=$rewriteTestApplication}'{unsafe:$rewriteTestApplication->getPackage()|encodeJS}': '{$__wcf->getPath($rewriteTestApplication->getAbbreviation())}core-rewrite-test/'{/implode}
37-
}));
34+
const apps = new Map(Object.entries(
35+
{unsafe:$rewriteTestApplications|json}
36+
));
3837
3938
AcpUiOptionRewriteTest.init(apps);
4039
});

wcfsetup/install/files/lib/acp/form/OptionForm.class.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use wcf\data\option\category\OptionCategory;
66
use wcf\data\option\OptionAction;
7+
use wcf\event\acp\option\RewriteApplicationCollecting;
78
use wcf\system\application\ApplicationHandler;
9+
use wcf\system\event\EventHandler;
810
use wcf\system\exception\IllegalLinkException;
911
use wcf\system\menu\acp\ACPMenu;
1012
use wcf\system\option\OptionHandler;
@@ -110,10 +112,24 @@ public function assignVariables()
110112
{
111113
parent::assignVariables();
112114

115+
$event = new RewriteApplicationCollecting();
116+
foreach (ApplicationHandler::getInstance()->getApplications() as $application) {
117+
$event->register($application->getPackage()->getName(), WCF::getPath($application->getAbbreviation()));
118+
}
119+
120+
EventHandler::getInstance()->fire($event);
121+
$applications = $event->getApplications();
122+
123+
// Generate a static route to enforce URL rewriting.
124+
$applications = \array_map(
125+
static fn(string $path) => $path . 'core-rewrite-test/',
126+
$applications
127+
);
128+
113129
WCF::getTPL()->assign([
114130
'category' => $this->category,
115131
'optionTree' => $this->optionTree,
116-
'rewriteTestApplications' => ApplicationHandler::getInstance()->getApplications(),
132+
'rewriteTestApplications' => $applications,
117133
]);
118134
}
119135

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace wcf\event\acp\option;
4+
5+
use wcf\event\IPsr14Event;
6+
7+
/**
8+
* Requests the collection additional applications for the rewrite configuration.
9+
*
10+
* @author Alexander Ebert
11+
* @copyright 2001-2025 WoltLab GmbH
12+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13+
* @since 6.2
14+
*/
15+
final class RewriteApplicationCollecting implements IPsr14Event
16+
{
17+
/**
18+
* @var array<string, string>
19+
*/
20+
private array $applications = [];
21+
22+
public function register(string $name, string $path): void
23+
{
24+
$this->applications[$name] = $path;
25+
}
26+
27+
/**
28+
* @return array<string, string>
29+
*/
30+
public function getApplications(): array
31+
{
32+
return $this->applications;
33+
}
34+
}

0 commit comments

Comments
 (0)