Skip to content

Rendering And Sync

Navigation owns editable navigation trees, render models, header render hooks, and page cleanup when URLs or replicated sites change.

SurfaceUse
BuildNavigationRenderModelActionBuilds the frontend render model.
NavigationNamesResolverResolves navigation names for a site and languages.
NavigationPageSyncerRemoves deleted or detached pages from navigation items.
RegisterFoundationHeaderNavigationHookAdds the foundation header navigation render hook.
NavigationObserverClears frontend navigation cache keys after changes.
ReplicateSiteNavigationsListenerCopies navigation rows when a site is replicated.
use Capell\Navigation\Actions\BuildNavigationRenderModelAction;
use Capell\Navigation\Data\NavigationRenderContextData;
use Capell\Navigation\Models\Navigation;
/** @var Navigation $navigation */
$renderModel = BuildNavigationRenderModelAction::run(
new NavigationRenderContextData(
navigation: $navigation,
page: $page,
site: $site,
language: $language,
siteDomain: $siteDomain,
),
);

Use the action from Blade view models or frontend components. Do not read the JSON column directly in templates.

NavigationNamesResolver lets host apps control the navigation names available for a site/language pair.

use Capell\Navigation\Contracts\NavigationNamesResolver;
final class DemoNavigationNamesResolver implements NavigationNamesResolver
{
public function resolve(?int $siteId, array $languageIds): array
{
return [
1 => 'Header',
2 => 'Footer',
];
}
}
$this->app->singleton(NavigationNamesResolver::class, DemoNavigationNamesResolver::class);

Return an array keyed by language ID. Keep names short because they appear in admin selects.

use Capell\Core\Contracts\Pageable;
use Capell\Navigation\Contracts\NavigationPageSyncer;
final class DemoNavigationPageSyncer implements NavigationPageSyncer
{
public function removePageFromAllNavigations(Pageable $page): void
{
// Remove references to the page from package-owned navigation payloads.
}
}

Bind a replacement only when another package owns the navigation payload shape. Otherwise use the default adapter.

Navigation changes clear frontend navigation cache keys through NavigationObserver. If another package caches rendered menus, it should clear those keys when it writes navigation items.

Terminal window
vendor/bin/pest packages/navigation/tests --configuration=phpunit.xml