@@ -50,16 +50,47 @@ public function __construct(ContainerInterface $container, RouterInterface $rout
50
50
*
51
51
* Options:
52
52
* - absoluteUrl (bool): Return absolute url (default: false)
53
+ * - route (string): Override the default backend route (default: contao_backend)
53
54
*
54
55
* @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
56
63
* @throws ContainerExceptionInterface
57
64
* @throws NotFoundExceptionInterface
58
- *
59
- * @return string The backend route url
60
65
*/
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
62
67
{
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
+
63
94
$ options = array_merge (
64
95
['absoluteUrl ' => false ],
65
96
$ options
@@ -79,7 +110,7 @@ public function generateBackendRoute(array $params = [], bool $addToken = true,
79
110
}
80
111
81
112
return $ this ->router ->generate (
82
- $ route ,
113
+ $ options [ ' route ' ] ?? ' contao_backend ' ,
83
114
$ params ,
84
115
$ options ['absoluteUrl ' ] ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH
85
116
);
0 commit comments