Skip to content

Commit 91e98ed

Browse files
committed
support handles by reference
1 parent fffbb3e commit 91e98ed

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/Http/Middleware/CacheTracker.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Statamic\Facades\URL;
1414
use Statamic\Forms;
1515
use Statamic\StaticCaching\Cacher;
16+
use Statamic\Structures\Nav;
1617
use Statamic\Structures\Page;
1718
use Statamic\Support\Str;
1819
use Statamic\Tags;
@@ -181,7 +182,13 @@ private function setupTagHooks()
181182
});
182183

183184
Tags\Nav::hook('init', function ($value, $next) use ($self) {
184-
$handle = 'nav:'.$this->params->get('handle', $this->tag != 'nav:index' ? Str::after($this->tag, 'nav:') : 'collection::pages');
185+
$handle = $this->params->get('handle', $this->tag != 'nav:index' ? Str::after($this->tag, 'nav:') : 'collection::pages');
186+
187+
if ($handle instanceof Nav) {
188+
$handle = $handle->handle();
189+
}
190+
191+
$handle = 'nav:'.$handle;
185192
$self->addContentTag($handle);
186193

187194
return $next($value);

tests/Unit/NavTagTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,41 @@ public function it_tracks_nav_tag_without_handle_using_default()
9898
$this->assertContains('nav:collection::pages', $tags);
9999
}
100100

101+
#[Test]
102+
public function it_tracks_nav_tag_when_handle_is_nav_instance()
103+
{
104+
// Create a navigation structure
105+
$nav = Facades\Nav::make('sidebar')
106+
->title('Sidebar')
107+
->expectsRoot(true)
108+
->collections(['pages'])
109+
->save();
110+
111+
$view = <<<'BLADE'
112+
{{ nav :handle="nav" }}
113+
{{ title }}
114+
{{ /nav }}
115+
BLADE;
116+
117+
file_put_contents($this->viewPath('nav-test.antlers.html'), $view);
118+
119+
Facades\Entry::make()
120+
->id('nav-test-page')
121+
->slug('nav-test')
122+
->collection('pages')
123+
->data([
124+
'template' => 'nav-test',
125+
'nav' => $nav,
126+
])
127+
->save();
128+
129+
$this->get('/nav-test');
130+
131+
$tags = collect(Tracker::all())->first()['tags'] ?? [];
132+
133+
$this->assertContains('nav:sidebar', $tags);
134+
}
135+
101136
protected function viewPath($name)
102137
{
103138
return __DIR__.'/../__fixtures__/resources/views/'.$name;

0 commit comments

Comments
 (0)