Skip to content

Commit

Permalink
Merge pull request #92 from art-institute-of-chicago/feature/landing-…
Browse files Browse the repository at this point in the history
…page-routes-and-relationships

Fix LPB routing and genericPage relationships [WEB-2596]
  • Loading branch information
nikhiltri authored Jul 26, 2023
2 parents 31c9b8e + abf30ff commit 4a16e68
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
9 changes: 9 additions & 0 deletions app/Http/Controllers/Admin/GenericPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ protected function formData($request)
];
}

protected function transformIndexItems($items)
{
// If we're in the browser, don't transform the items
if (property_exists($items, 'path')) {
return $items;
}
return $items->toTree();
}

protected function indexItemData($item)
{
return $item->children ? [
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/LandingPagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function show($id, $slug = null)
return $canonicalRedirect;
}

if (!$item->is_published) {
$this->seo->nofollow = true;
$this->seo->noindex = true;
}

// Home
$mainHomeFeatures = $item->mainHomeFeatures()->published()->limit(1)->get();
$secondaryHomeFeatures = $item->secondaryHomeFeatures()->published()->limit(2)->get();
Expand Down
27 changes: 4 additions & 23 deletions app/Http/Middleware/ResolvePageRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ public function handle(Request $request, Closure $next)
}

$landingPageModel = LandingPage::published()->join('landing_page_slugs', function ($join) use ($slug) {
$join->on('landing_page_slugs.landing_page_id', 'landing_pages.id')->where('landing_page_slugs.slug', $slug);
$join->on('landing_page_slugs.landing_page_id', 'landing_pages.id')
->where('landing_page_slugs.slug', $slug)
->where('landing_page_slugs.active', true);
})->first();


if ($landingPageModel) {
// To satisfy the HTTP protocol we need to generate a response from the controller as if we were going there

// Create a new request here
$newRequest = Request::create(
route('landingPages.show', ['id' => $landingPageModel->id, 'slug' => $slug]),
route('landingPages.show', ['id' => $landingPageModel->landing_page_id, 'slug' => $slug]),
'GET',
[],
$request->cookie(),
Expand All @@ -49,26 +50,6 @@ public function handle(Request $request, Closure $next)
return $response;
}

$genericPageModel = GenericPage::published()->join('generic_page_slugs', function ($join) use ($slug) {
$join->on('generic_page_slugs.generic_page_id', 'generic_pages.id')->where('generic_page_slugs.slug', $slug);
})->first();


if ($genericPageModel) {
$newRequest = Request::create(
route('genericPage.show', ['id' => $genericPageModel->id, 'slug' => $slug]),
'GET',
[],
$request->cookie(),
[],
$request->server()
);

$response = app()->handle($newRequest);

return $response;
}

return $next($request);
}
}

0 comments on commit 4a16e68

Please sign in to comment.