Skip to content

Commit 578246c

Browse files
committed
minor #1441 Update documentation links (smnandre)
This PR was squashed before being merged into the main branch. Discussion ---------- Update documentation links * update doclinks.js (and remove jquery usage) * update some links in BlogController * remove references to SensioFrameworkExtraBundle Commits ------- cec5eb3 Update documentation links
2 parents 27f08c4 + cec5eb3 commit 578246c

File tree

2 files changed

+33
-40
lines changed

2 files changed

+33
-40
lines changed

assets/js/doclinks.js

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,54 @@
11
'use strict';
22

33
// Wraps some elements in anchor tags referencing to the Symfony documentation
4-
$(function() {
5-
var $modal = $('#sourceCodeModal');
6-
var $controllerCode = $modal.find('code.php');
7-
var $templateCode = $modal.find('code.twig');
4+
document.addEventListener('DOMContentLoaded', function() {
5+
const modalElt = document.querySelector('#sourceCodeModal');
6+
if (!modalElt) {
7+
return;
8+
}
9+
const controllerCode = modalElt.querySelector('code.php');
10+
const templateCode = modalElt.querySelector('code.twig');
811

912
function anchor(url, content) {
1013
return '<a class="doclink" target="_blank" href="' + url + '">' + content + '</a>';
11-
};
14+
}
1215

1316
function wrap(content, links) {
1417
return content.replace(
1518
new RegExp(Object.keys(links).join('|'), 'g'),
1619
token => anchor(links[token], token)
1720
);
18-
};
21+
}
1922

20-
// Wraps links to the Symfony documentation
21-
$modal.find('.hljs-comment').each(function() {
22-
$(this).html($(this).html().replace(/https:\/\/symfony.com\/doc\/[\w/.#-]+/g, function(url) {
23-
return anchor(url, url);
24-
}));
23+
// Wrap Symfony Doc urls in comments
24+
[...modalElt.querySelectorAll('.hljs-comment')].forEach((commentElt) => {
25+
commentElt.innerHTML = commentElt.innerHTML.replace(/https:\/\/symfony.com\/[\w/.#-]+/g, (url) => anchor(url, url));
2526
});
2627

27-
// Wraps Symfony's attributes
28-
var attributes = {
29-
'Cache': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/cache.html',
30-
'IsGranted': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html#isgranted',
31-
'ParamConverter': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html',
32-
'Route': 'https://symfony.com/doc/current/routing.html#creating-routes-as-attributes-or-annotations',
33-
'Security': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html#security'
28+
// Wraps Symfony PHP attributes in code
29+
const attributes = {
30+
'Cache': 'https://symfony.com/doc/current/http_cache.html#http-cache-expiration-intro',
31+
'Route': 'https://symfony.com/doc/current/routing.html#creating-routes-as-attributes',
32+
'IsGranted': 'https://symfony.com/doc/current/security.html#security-securing-controller-annotations'
3433
};
35-
36-
$controllerCode.find('.hljs-meta').each(function() {
37-
var src = $(this).text();
38-
39-
$(this).html(wrap(src, attributes));
34+
[...controllerCode.querySelectorAll('.hljs-meta')].forEach((elt) => {
35+
elt.innerHTML = wrap(elt.textContent, attributes);
4036
});
4137

4238
// Wraps Twig's tags
43-
$templateCode.find('.hljs-template-tag + .hljs-name').each(function() {
44-
var tag = $(this).text();
45-
39+
[...templateCode.querySelectorAll('.hljs-template-tag + .hljs-name')].forEach((elt) => {
40+
const tag = elt.textContent;
4641
if ('else' === tag || tag.match(/^end/)) {
4742
return;
4843
}
49-
50-
var url = 'https://twig.symfony.com/doc/3.x/tags/' + tag + '.html#' + tag;
51-
52-
$(this).html(anchor(url, tag));
44+
const url = 'https://twig.symfony.com/doc/3.x/tags/' + tag + '.html#' + tag;
45+
elt.innerHTML = anchor(url, tag);
5346
});
5447

5548
// Wraps Twig's functions
56-
$templateCode.find('.hljs-template-variable > .hljs-name').each(function() {
57-
var func = $(this).text();
58-
59-
var url = 'https://twig.symfony.com/doc/3.x/functions/' + func + '.html#' + func;
60-
61-
$(this).html(anchor(url, func));
49+
[...templateCode.querySelectorAll('.hljs-template-variable > .hljs-name')].forEach((elt) => {
50+
const func = elt.textContent;
51+
const url = 'https://twig.symfony.com/doc/3.x/functions/' + func + '.html#' + func;
52+
elt.innerHTML = anchor(url, func);
6253
});
6354
});

src/Controller/BlogController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function index(Request $request, int $page, string $_format, PostReposito
7070
* after performing a database query looking for a Post with the 'slug'
7171
* value given in the route.
7272
*
73-
* See https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
73+
* See https://symfony.com/doc/current/doctrine.html#automatically-fetching-objects-entityvalueresolver
7474
*/
7575
#[Route('/posts/{slug}', name: 'blog_post', methods: ['GET'])]
7676
public function postShow(Post $post): Response
@@ -93,10 +93,10 @@ public function postShow(Post $post): Response
9393
}
9494

9595
/**
96-
* NOTE: The ParamConverter mapping is required because the route parameter
96+
* NOTE: The #[MapEntity] mapping is required because the route parameter
9797
* (postSlug) doesn't match any of the Doctrine entity properties (slug).
9898
*
99-
* See https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html#doctrine-converter
99+
* See https://symfony.com/doc/current/doctrine.html#doctrine-entity-value-resolver
100100
*/
101101
#[Route('/comment/{postSlug}/new', name: 'comment_new', methods: ['POST'])]
102102
#[IsGranted('IS_AUTHENTICATED')]
@@ -140,7 +140,9 @@ public function commentNew(
140140
* a route name for it.
141141
*
142142
* The "id" of the Post is passed in and then turned into a Post object
143-
* automatically by the ParamConverter.
143+
* automatically by the ValueResolver.
144+
*
145+
* See https://symfony.com/doc/current/doctrine.html#automatically-fetching-objects-entityvalueresolver
144146
*/
145147
public function commentForm(Post $post): Response
146148
{

0 commit comments

Comments
 (0)