Skip to content

Commit 031b87e

Browse files
authored
Use fragments for nav elements (#126)
* upgrade to Symfony 7.3 * upgrade dependencies * global and lang navigations now use fragments * fix url generation when using cli * update deps * fix menus in other languages * configure default locale with environment variable and allow generating menus in different languages, even in the context of CLI * update deps * set default_uri to the value of $APP_URL
1 parent 18285bc commit 031b87e

File tree

16 files changed

+70
-81
lines changed

16 files changed

+70
-81
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ CORS_ALLOW_ORIGIN='*'
3434
# Dev settings are detailed below, please override in .env.$APP_ENV or .env.local (for secrets)
3535
# Please set APP_ENV application environment in your .env.local file
3636

37+
APP_DEFAULT_LOCALE=en
3738
APP_URL=https://www-dev.w3.org
3839

3940
# Craft CMS API URL

composer.lock

Lines changed: 40 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/packages/routing.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ framework:
22
router:
33
# Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
44
# See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
5-
#default_uri: http://localhost
5+
default_uri: '%env(APP_URL)%'
66

77
when@prod:
88
framework:

config/packages/translation.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
framework:
2-
default_locale: en
2+
default_locale: '%env(APP_DEFAULT_LOCALE)%'
33
translator:
44
default_path: '%kernel.project_dir%/translations'
55
fallbacks:
6-
- en
6+
- '%env(APP_DEFAULT_LOCALE)%'

config/packages/twig.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
twig:
22
default_path: '%kernel.project_dir%/templates'
3+
globals:
4+
default_locale: '%env(APP_DEFAULT_LOCALE)%'

src/Controller/BlogController.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function index(
6666
throw $this->createNotFoundException();
6767
}
6868
$search = $request->query->get('search');
69-
69+
7070
$manager->add('page', new Listing($site->siteHandle));
7171
$manager->add(
7272
'collection',
@@ -100,7 +100,6 @@ public function index(
100100

101101
return $this->render('blog/index.html.twig', [
102102
'site' => $site,
103-
'navigation' => $manager->getCollection('navigation'),
104103
'page' => $page,
105104
'entries' => $collection,
106105
'pagination' => $collection->getPagination(),
@@ -177,7 +176,6 @@ public function archive(
177176

178177
return $this->render('blog/index.html.twig', [
179178
'site' => $site,
180-
'navigation' => $manager->getCollection('navigation'),
181179
'page' => $page,
182180
'entries' => $collection,
183181
'pagination' => $collection->getPagination(),
@@ -274,7 +272,6 @@ public function category(
274272

275273
return $this->render('blog/index.html.twig', [
276274
'site' => $site,
277-
'navigation' => $manager->getCollection('navigation'),
278275
'page' => $page,
279276
'entries' => $collection,
280277
'pagination' => $collection->getPagination(),
@@ -364,7 +361,6 @@ public function tag(
364361

365362
return $this->render('blog/index.html.twig', [
366363
'site' => $site,
367-
'navigation' => $manager->getCollection('navigation'),
368364
'page' => $page,
369365
'entries' => $collection,
370366
'pagination' => $collection->getPagination(),
@@ -505,7 +501,6 @@ public function show(
505501

506502
return $this->render('blog/show.html.twig', [
507503
'site' => $site,
508-
'navigation' => $manager->getCollection('navigation'),
509504
'page' => $page,
510505
'crosslinks' => $crosslinks,
511506
'comments' => $topLevelComms,

src/Controller/DefaultController.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public function debug(QueryManager $manager, RouterInterface $router): Response
4646

4747
$response = $this->render('debug/test.html.twig', [
4848
'title' => 'Debug page',
49-
'navigation' => $manager->getCollection('navigation'),
50-
'navigation_cached' => $manager->isHit('navigation'),
5149
'w3c_available' => $manager->getQuery('w3c_healthcheck')->isHealthy(),
5250
'page' => $manager->get('page'),
5351
'page_cached' => $manager->isHit('page'),
@@ -80,8 +78,6 @@ public function home(
8078
$manager->add('recent-activities', new RecentActivities($site->siteHandle, $router));
8179
$manager->add('members', new Members());
8280

83-
$navigation = $manager->getCollection('navigation');
84-
8581
$page = $manager->get('page');
8682
$recentActivities = $manager->getCollection('recent-activities');
8783

@@ -112,9 +108,9 @@ public function home(
112108

113109
$response = $this->render(
114110
'pages/home.html.twig',
115-
['page' => $page, 'members' => $members, 'navigation' => $navigation]
111+
['page' => $page, 'members' => $members]
116112
);
117-
113+
118114
return $response;
119115
}
120116

@@ -146,14 +142,11 @@ public function index(
146142
throw $this->createNotFoundException('Page not found');
147143
}
148144

149-
$navigation = $manager->getCollection('navigation');
150-
151145
$manager->add('crosslinks', new YouMayAlsoLikeRelatedEntries($router, $site->siteHandle, (int)$page['id']));
152146
$crosslinks = $manager->get('crosslinks');
153147

154148
//Only for testing purposes in dev
155149
$twig_variables = array(
156-
'navigation' => $navigation,
157150
'page' => $page,
158151
'crosslinks' => $crosslinks
159152
);
@@ -169,7 +162,6 @@ public function index(
169162

170163
return $this->render($template, [
171164
'site' => $site,
172-
'navigation' => $navigation,
173165
'page' => $page,
174166
'crosslinks' => $crosslinks,
175167
'related_links' => array_key_exists('siblings', $page) ? $page['siblings'] : null

src/Controller/EcosystemController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ public function show(string $slug, Site $site, QueryManager $manager, RouterInte
151151

152152
return $this->render('ecosystems/show.html.twig', [
153153
'site' => $site,
154-
'navigation' => $manager->getCollection('navigation'),
155154
'page' => $page,
156155
]);
157156
}

0 commit comments

Comments
 (0)