File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,15 @@ protected function isMissingContext($context)
2626
2727 protected function getContextFromCascade ()
2828 {
29- return Cascade::instance ()->toArray ();
29+ $ cascade = Cascade::instance ();
30+
31+ // If the cascade has not yet been hydrated, ensure it is hydrated.
32+ // This is important for people using custom route/controller/view implementations.
33+ if (empty ($ cascade ->toArray ())) {
34+ $ cascade ->hydrate ();
35+ }
36+
37+ return $ cascade ->toArray ();
3038 }
3139
3240 protected function getContextFromCurrentRouteData ()
Original file line number Diff line number Diff line change 22
33namespace Tests ;
44
5+ use Facades \Statamic \View \Cascade as StatamicViewCacade ;
56use Illuminate \Pagination \LengthAwarePaginator ;
67use Illuminate \Support \Facades \Artisan ;
78use Illuminate \Support \Facades \Route ;
@@ -27,6 +28,14 @@ protected function getEnvironmentSetUp($app)
2728 'title ' => 'The View ' ,
2829 'description ' => 'A wonderful view! ' ,
2930 ]);
31+
32+ Route::get ('custom-get-route ' , function () {
33+ StatamicViewCacade::hydrated (function ($ cascade ) {
34+ $ cascade ->set ('title ' , 'Custom Route Entry Title ' );
35+ });
36+
37+ return view ('page ' );
38+ });
3039 });
3140 }
3241
@@ -746,6 +755,24 @@ public function it_generates_normalized_meta_from_custom_site_defaults_path($vie
746755 $ this ->assertStringContainsString ($ this ->normalizeMultilineString ($ expected ), $ content );
747756 }
748757
758+ /**
759+ * @test
760+ *
761+ * @dataProvider viewScenarioProvider
762+ */
763+ public function it_hydrates_cascade_on_custom_routes_using_blade_directive ($ viewType )
764+ {
765+ if ($ viewType === 'antlers ' ) {
766+ $ this ->markTestSkipped ();
767+ }
768+
769+ $ this ->prepareViews ($ viewType );
770+
771+ $ content = $ this ->get ('/custom-get-route ' )->content ();
772+
773+ $ this ->assertStringContainsString ('<title>Custom Route Entry Title | Site Name</title> ' , $ content );
774+ }
775+
749776 protected function setCustomGlidePresetDimensions ($ app )
750777 {
751778 $ app ->config ->set ('statamic.seo-pro.assets ' , [
You can’t perform that action at this time.
0 commit comments