Skip to content

Commit

Permalink
nested breadcrumbs route prefix support
Browse files Browse the repository at this point in the history
  • Loading branch information
yamaha252 authored and ifox committed Aug 5, 2023
1 parent edd0f57 commit 6be8bfc
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Services/Breadcrumbs/NestedBreadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class NestedBreadcrumbs extends Breadcrumbs
private int $activeParentId;
private string $titleKey;
private string $label;
private string $routePrefix = '';

public function parentLabel(string $parentLabel): self
{
Expand All @@ -26,13 +27,15 @@ public function forParent(
string $module,
int $activeParentId,
string $repository,
?string $titleKey = 'title'
?string $titleKey = 'title',
?string $routePrefix = '',
): self {
$this->module = $module;
$this->parentModule = $parentModule;
$this->parentRepository = $repository;
$this->activeParentId = $activeParentId;
$this->titleKey = $titleKey;
$this->routePrefix = $routePrefix;

if (!$this->parentLabel) {
$this->parentLabel(Str::title($parentModule));
Expand Down Expand Up @@ -61,16 +64,16 @@ public function toArray(): array
BreadcrumbItem::make()->label($this->parentLabel)
->displayOnForm()
->displayOnListing()
->url(moduleRoute($this->parentModule, '', 'index')),
->url(moduleRoute($this->parentModule, $this->routePrefix, 'index')),
BreadcrumbItem::make()->label($this->getActiveParentTitle())
->displayOnForm()
->displayOnListing()
->url(moduleRoute($this->parentModule, '', 'edit', $this->activeParentId)),
->url(moduleRoute($this->parentModule, $this->routePrefix, 'edit', $this->activeParentId)),
BreadcrumbItem::make()->label($this->label)
->displayOnListing(),
BreadcrumbItem::make()->label($this->label)
->displayOnForm()
->url(moduleRoute($this->module, '', 'index')),
->url(moduleRoute($this->module, $this->routePrefix, 'index')),
BreadcrumbItem::make()->label('Edit')
->displayOnForm(),
];
Expand Down

0 comments on commit 6be8bfc

Please sign in to comment.