44
55use Code16 \Sharp \Exceptions \SharpInvalidBreadcrumbItemException ;
66use Code16 \Sharp \Http \Context \Util \BreadcrumbItem ;
7+ use Code16 \Sharp \Utils \Entities \SharpEntityManager ;
78use Illuminate \Support \Traits \Conditionable ;
89
910class BreadcrumbBuilder
@@ -12,34 +13,37 @@ class BreadcrumbBuilder
1213
1314 protected array $ breadcrumbParts = [];
1415
15- public function appendEntityList (string $ entityKey ): self
16+ public function appendEntityList (string $ entityClassNameOrKey ): self
1617 {
1718 if (! empty ($ this ->breadcrumbParts )) {
1819 throw new SharpInvalidBreadcrumbItemException ('Entity list must be the first breadcrumb item ' );
1920 }
2021
22+ $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
2123 $ this ->breadcrumbParts [] = new BreadcrumbItem ('s-list ' , $ entityKey );
2224
2325 return $ this ;
2426 }
2527
26- public function appendSingleShowPage (string $ entityKey ): self
28+ public function appendSingleShowPage (string $ entityClassNameOrKey ): self
2729 {
2830 if (! empty ($ this ->breadcrumbParts )) {
2931 throw new SharpInvalidBreadcrumbItemException ('Single show page must be the first breadcrumb item ' );
3032 }
3133
34+ $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
3235 $ this ->breadcrumbParts [] = new BreadcrumbItem ('s-show ' , $ entityKey );
3336
3437 return $ this ;
3538 }
3639
37- public function appendShowPage (string $ entityKey , string $ instanceId ): self
40+ public function appendShowPage (string $ entityClassNameOrKey , string $ instanceId ): self
3841 {
3942 if (empty ($ this ->breadcrumbParts )) {
4043 throw new SharpInvalidBreadcrumbItemException ('Show page can not be the first breadcrumb item ' );
4144 }
4245
46+ $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
4347 $ this ->breadcrumbParts [] = (new BreadcrumbItem ('s-show ' , $ entityKey ))->setInstance ($ instanceId );
4448
4549 return $ this ;
@@ -51,4 +55,11 @@ public function generateUri(): string
5155 ->map (fn (BreadcrumbItem $ item ) => $ item ->toUri ())
5256 ->implode ('/ ' );
5357 }
58+
59+ private function resolveEntityKey (string $ entityClassNameOrKey ): string
60+ {
61+ return class_exists ($ entityClassNameOrKey )
62+ ? app (SharpEntityManager::class)->entityKeyFor ($ entityClassNameOrKey )
63+ : $ entityClassNameOrKey ;
64+ }
5465}
0 commit comments