File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed
Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 1313use Statamic \Facades \URL ;
1414use Statamic \Forms ;
1515use Statamic \StaticCaching \Cacher ;
16+ use Statamic \Structures \Nav ;
1617use Statamic \Structures \Page ;
1718use Statamic \Support \Str ;
1819use 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 );
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments