@@ -63,7 +63,8 @@ public function __construct(
63
63
private readonly UrlGeneratorInterface $ router ,
64
64
protected bool $ rootNodeExpandedByDefault ,
65
65
protected bool $ rootNodeEnabled ,
66
-
66
+ //TODO: Make this configurable in the future
67
+ protected bool $ rootNodeRedirectsToNewEntity = false ,
67
68
) {
68
69
}
69
70
@@ -174,10 +175,7 @@ private function getTreeViewUncached(
174
175
}
175
176
176
177
if (($ mode === 'list_parts_root ' || $ mode === 'devices ' ) && $ this ->rootNodeEnabled ) {
177
- //We show the root node as a link to the list of all parts
178
- $ show_all_parts_url = $ this ->router ->generate ('parts_show_all ' );
179
-
180
- $ root_node = new TreeViewNode ($ this ->entityClassToRootNodeString ($ class ), $ show_all_parts_url , $ generic );
178
+ $ root_node = new TreeViewNode ($ this ->entityClassToRootNodeString ($ class ), $ this ->entityClassToRootNodeHref ($ class ), $ generic );
181
179
$ root_node ->setExpanded ($ this ->rootNodeExpandedByDefault );
182
180
$ root_node ->setIcon ($ this ->entityClassToRootNodeIcon ($ class ));
183
181
@@ -187,6 +185,27 @@ private function getTreeViewUncached(
187
185
return array_merge ($ head , $ generic );
188
186
}
189
187
188
+ protected function entityClassToRootNodeHref (string $ class ): ?string
189
+ {
190
+ //If the root node should redirect to the new entity page, we return the URL for the new entity.
191
+ if ($ this ->rootNodeRedirectsToNewEntity ) {
192
+ return match ($ class ) {
193
+ Category::class => $ this ->router ->generate ('category_new ' ),
194
+ StorageLocation::class => $ this ->router ->generate ('store_location_new ' ),
195
+ Footprint::class => $ this ->router ->generate ('footprint_new ' ),
196
+ Manufacturer::class => $ this ->router ->generate ('manufacturer_new ' ),
197
+ Supplier::class => $ this ->router ->generate ('supplier_new ' ),
198
+ Project::class => $ this ->router ->generate ('project_new ' ),
199
+ default => null ,
200
+ };
201
+ }
202
+
203
+ return match ($ class ) {
204
+ Project::class => $ this ->router ->generate ('project_new ' ),
205
+ default => $ this ->router ->generate ('parts_show_all ' )
206
+ };
207
+ }
208
+
190
209
protected function entityClassToRootNodeString (string $ class ): string
191
210
{
192
211
return match ($ class ) {
0 commit comments