Skip to content

Commit 6d57673

Browse files
committed
make RoutingUtil::generateBackendRoute signature compatible with v2
1 parent 4481c9f commit 6d57673

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/Util/Routing/RoutingUtil.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,47 @@ public function __construct(ContainerInterface $container, RouterInterface $rout
5050
*
5151
* Options:
5252
* - absoluteUrl (bool): Return absolute url (default: false)
53+
* - route (string): Override the default backend route (default: contao_backend)
5354
*
5455
* @param array $params Url-Parameters
55-
*
56+
* @param bool $addToken
57+
* @param bool $addReferer
58+
* @param array{
59+
* route: string,
60+
* absoluteUrl: bool,
61+
* }|string $options
62+
* @return string The backend route url
5663
* @throws ContainerExceptionInterface
5764
* @throws NotFoundExceptionInterface
58-
*
59-
* @return string The backend route url
6065
*/
61-
public function generateBackendRoute(array $params = [], bool $addToken = true, bool $addReferer = true, string $route = 'contao_backend', array $options = []): string
66+
public function generateBackendRoute(array $params = [], bool $addToken = true, bool $addReferer = true, $options = []): string
6267
{
68+
if (is_string($options)) {
69+
trigger_deprecation(
70+
'heimrichhannot/contao-utils-bundle',
71+
'2.244.0',
72+
'Passing a string as fourth parameter is deprecated. Use an array with the key "route" instead.'
73+
);
74+
$options = ['route' => $options];
75+
} elseif (!is_array($options)) {
76+
throw new \InvalidArgumentException('Fourth parameter must be a string or an array.');
77+
}
78+
79+
// support legacy method signature
80+
if (func_num_args() > 4) {
81+
trigger_deprecation(
82+
'heimrichhannot/contao-utils-bundle',
83+
'2.244.0',
84+
'Passing more than four parameters is deprecated. Use an array as fourth parameter with the key "route" instead.'
85+
);
86+
$oldOptions = func_get_arg(4);
87+
if (is_array($oldOptions)) {
88+
$options = array_merge($options, $oldOptions);
89+
} else {
90+
throw new \InvalidArgumentException('Fifth parameter must be an array.');
91+
}
92+
}
93+
6394
$options = array_merge(
6495
['absoluteUrl' => false],
6596
$options
@@ -79,7 +110,7 @@ public function generateBackendRoute(array $params = [], bool $addToken = true,
79110
}
80111

81112
return $this->router->generate(
82-
$route,
113+
$options['route'] ?? 'contao_backend',
83114
$params,
84115
$options['absoluteUrl'] ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH
85116
);

0 commit comments

Comments
 (0)