Skip to content

Commit

Permalink
Add filter selections to page titles [WEB-2998]
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiltri committed Jan 10, 2025
1 parent 1f6bff7 commit d0e0d0c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
15 changes: 15 additions & 0 deletions app/Http/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ public function index()
);
}

if (request('category') || request('type')) {
$cat = $page->articlesCategories->first(function ($value) {
return $value->id == request('category');
});
$titles = array_filter([
'Articles',
$cat?->name,
Str::title(request('type')),
request('page') ? 'Page ' . request('page') : null,
]);
$this->seo->setTitle(implode(', ', $titles));
} else {
$this->seo->setTitle('Articles');
}

return view('site.articles', [
'primaryNavCurrent' => 'collection',
'page' => $page,
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/EducatorResourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ public function index(Request $request)
$items = $this->collection()->orderByDate()->paginate();

$title = 'Educator Resources';
$cat = ResourceCategory::where('id', request('category'))->first();
$titles = array_filter([
$title,
$cat?->name,
request('page') ? 'Page ' . request('page') : null,
]);

$this->seo->setTitle($title);
$this->seo->setTitle(implode(', ', $titles));

$subNav = [
['label' => $title, 'href' => route('collection.resources.educator-resources'), 'active' => true]
Expand Down
24 changes: 23 additions & 1 deletion app/Http/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\EventProgram;
use App\Repositories\EventRepository;
use Carbon\Carbon;
use Illuminate\Support\Str;
use View;

class EventsController extends FrontController
Expand Down Expand Up @@ -39,9 +40,30 @@ public function index()
$ongoing = null;
$eventsByDay = $this->repository->groupByDate($collection);

$programName = null;
if (request('program')) {
$subtitle = 'These are events related to ' . EventProgram::find(request('program'))->name . '.';
$programName = EventProgram::find(request('program'))->name;
$subtitle = 'These are events related to ' . $programName . '.';
}

$type = collect(Event::$eventTypes)->first(function ($value, $key) {
return $key == request('type');
});
$audience = collect(Event::$eventAudiences)->first(function ($value, $key) {
return $key == request('audience');
});
$titles = array_filter([
'Events',
request('start') ? Carbon::parse(request('start'))->toFormattedDateString() : null,
request('end') ? Carbon::parse(request('end'))->toFormattedDateString() : null,
Str::title(request('time')),
$type,
$audience,
$programName,
request('page') ? 'Page ' . request('page') : null,
]);

$this->seo->setTitle(implode(', ', $titles));
} else {
// Divide the collection by normal events and ongoing ones
$ongoing = $collection->filter(function ($item) {
Expand Down
8 changes: 8 additions & 0 deletions app/Http/Controllers/ExhibitionHistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public function index(Request $request, ExhibitionHistoryService $service)
$extraResults = $this->apiRepository->searchApi(request('q'), self::PER_PAGE);
}

$titles = array_filter([
'Exhibition History',
request('year'),
request('page') ? 'Page ' . request('page') : null,
]);

$this->seo->setTitle(implode(', ', $titles));

$viewData = [
'page' => $page,
'years' => $years,
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/PrintedPublicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ public function index(Request $request)
$items = $this->collection()->ordered()->paginate();

$title = 'Print Publications';
$cat = CatalogCategory::where('id', request('category'))->first();

$this->seo->setTitle($title);
$titles = array_filter([
$title,
$cat?->name,
request('page') ? 'Page ' . request('page') : null,
]);
$this->seo->setTitle(implode(', ', $titles));

$navElements = NavHelpers::get_nav_for_publications($title);

Expand Down

0 comments on commit d0e0d0c

Please sign in to comment.