@@ -63,7 +63,8 @@ public function __construct(
6363 private readonly UrlGeneratorInterface $ router ,
6464 protected bool $ rootNodeExpandedByDefault ,
6565 protected bool $ rootNodeEnabled ,
66-
66+ //TODO: Make this configurable in the future
67+ protected bool $ rootNodeRedirectsToNewEntity = false ,
6768 ) {
6869 }
6970
@@ -174,10 +175,7 @@ private function getTreeViewUncached(
174175 }
175176
176177 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 );
181179 $ root_node ->setExpanded ($ this ->rootNodeExpandedByDefault );
182180 $ root_node ->setIcon ($ this ->entityClassToRootNodeIcon ($ class ));
183181
@@ -187,6 +185,27 @@ private function getTreeViewUncached(
187185 return array_merge ($ head , $ generic );
188186 }
189187
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+
190209 protected function entityClassToRootNodeString (string $ class ): string
191210 {
192211 return match ($ class ) {
0 commit comments