Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CP/Navigation/CoreNav.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ protected function makeContentSection()
})
->map(function ($collection) {
return Nav::item($collection->title())
->id('content::collections::'.$collection->handle())
->url(
$collection->sites()->contains(Site::selected()->handle())
? $collection->showUrl()
Expand Down Expand Up @@ -122,6 +123,7 @@ protected function makeContentSection()
: true;

return Nav::item($nav->title())
->id('content::navigation::'.$nav->handle())
->url($availableInSelectedSite ? $nav->showUrl() : $nav->editUrl())
->can('view', $nav)
->extra([
Expand All @@ -145,6 +147,7 @@ protected function makeContentSection()
->children(function () {
return TaxonomyAPI::all()->sortBy->title()->map(function ($taxonomy) {
return Nav::item($taxonomy->title())
->id('content::taxonomies::'.$taxonomy->handle())
->url($taxonomy->showUrl())
->can('view', $taxonomy)
->extra([
Expand All @@ -168,6 +171,7 @@ protected function makeContentSection()
->children(function () {
return AssetContainerAPI::all()->sortBy->title()->map(function ($assetContainer) {
return Nav::item($assetContainer->title())
->id('content::assets::'.$assetContainer->handle())
->url($assetContainer->showUrl())
->can('view', $assetContainer)
->extra([
Expand Down Expand Up @@ -198,6 +202,7 @@ protected function makeContentSection()
$localized = $globalSet->inSelectedSite();

return Nav::item($globalSet->title())
->id('content::globals::'.$globalSet->handle())
->url($localized ? $localized->editUrl() : $globalSet->editUrl())
->can('view', $globalSet)
->extra([
Expand Down Expand Up @@ -251,6 +256,7 @@ protected function makeToolsSection()
->children(function () {
return FormAPI::all()->sortBy->title()->map(function ($form) {
return Nav::item($form->title())
->id('tools::forms::'.$form->handle())
->url($form->showUrl())
->can('view', $form)
->extra(['breadcrumbs' => ['configure_url' => $form->editUrl()]]);
Expand Down
22 changes: 21 additions & 1 deletion src/CP/Navigation/NavBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,27 @@ protected function findItem($id, $removeAliasHash = true)
}
}

return $items->get($id);
return $items->get($id) ?? $this->findItemByLegacyId($id);
}

/**
* Find existing nav item by the ID it would have been given before child IDs
* were generated from handles, so that preferences saved against the older
* display-based IDs continue to work.
*
* @param string $id
* @return \Statamic\CP\Navigation\NavItem|null
*/
protected function findItemByLegacyId($id)
{
if (! $parent = $this->findParentItem($id)) {
return null;
}

return $parent
->resolveChildren()
->children()
?->first(fn ($child) => $parent->id().'::'.NavItem::snakeCase($child->display()) === $id);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/CP/Navigation/NavItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ public function id($id = null)
->value($id);
}

/**
* Check if an ID has been explicitly set, rather than generated from the display.
*
* @return bool
*/
public function hasCustomId()
{
return ! is_null($this->id);
}

/**
* Preserve current ID.
*
Expand Down Expand Up @@ -277,7 +287,7 @@ public function children($items = null, $generateNewIds = true)
})
->map(function ($navItem) use ($generateNewIds) {
return $navItem
->id($generateNewIds ? $this->id().'::' : $navItem->id())
->id($generateNewIds && ! $navItem->hasCustomId() ? $this->id().'::' : $navItem->id())
->icon($navItem->icon() ?? $this->icon())
->section($this->section())
->isChild(true);
Expand Down
Loading