diff --git a/assets/js/doclinks.js b/assets/js/doclinks.js index 89c5c2a11..fc048bcf0 100644 --- a/assets/js/doclinks.js +++ b/assets/js/doclinks.js @@ -1,63 +1,54 @@ 'use strict'; // Wraps some elements in anchor tags referencing to the Symfony documentation -$(function() { - var $modal = $('#sourceCodeModal'); - var $controllerCode = $modal.find('code.php'); - var $templateCode = $modal.find('code.twig'); +document.addEventListener('DOMContentLoaded', function() { + const modalElt = document.querySelector('#sourceCodeModal'); + if (!modalElt) { + return; + } + const controllerCode = modalElt.querySelector('code.php'); + const templateCode = modalElt.querySelector('code.twig'); function anchor(url, content) { return '' + content + ''; - }; + } function wrap(content, links) { return content.replace( new RegExp(Object.keys(links).join('|'), 'g'), token => anchor(links[token], token) ); - }; + } - // Wraps links to the Symfony documentation - $modal.find('.hljs-comment').each(function() { - $(this).html($(this).html().replace(/https:\/\/symfony.com\/doc\/[\w/.#-]+/g, function(url) { - return anchor(url, url); - })); + // Wrap Symfony Doc urls in comments + [...modalElt.querySelectorAll('.hljs-comment')].forEach((commentElt) => { + commentElt.innerHTML = commentElt.innerHTML.replace(/https:\/\/symfony.com\/[\w/.#-]+/g, (url) => anchor(url, url)); }); - // Wraps Symfony's attributes - var attributes = { - 'Cache': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/cache.html', - 'IsGranted': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html#isgranted', - 'ParamConverter': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html', - 'Route': 'https://symfony.com/doc/current/routing.html#creating-routes-as-attributes-or-annotations', - 'Security': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html#security' + // Wraps Symfony PHP attributes in code + const attributes = { + 'Cache': 'https://symfony.com/doc/current/http_cache.html#http-cache-expiration-intro', + 'Route': 'https://symfony.com/doc/current/routing.html#creating-routes-as-attributes', + 'IsGranted': 'https://symfony.com/doc/current/security.html#security-securing-controller-annotations' }; - - $controllerCode.find('.hljs-meta').each(function() { - var src = $(this).text(); - - $(this).html(wrap(src, attributes)); + [...controllerCode.querySelectorAll('.hljs-meta')].forEach((elt) => { + elt.innerHTML = wrap(elt.textContent, attributes); }); // Wraps Twig's tags - $templateCode.find('.hljs-template-tag + .hljs-name').each(function() { - var tag = $(this).text(); - + [...templateCode.querySelectorAll('.hljs-template-tag + .hljs-name')].forEach((elt) => { + const tag = elt.textContent; if ('else' === tag || tag.match(/^end/)) { return; } - - var url = 'https://twig.symfony.com/doc/3.x/tags/' + tag + '.html#' + tag; - - $(this).html(anchor(url, tag)); + const url = 'https://twig.symfony.com/doc/3.x/tags/' + tag + '.html#' + tag; + elt.innerHTML = anchor(url, tag); }); // Wraps Twig's functions - $templateCode.find('.hljs-template-variable > .hljs-name').each(function() { - var func = $(this).text(); - - var url = 'https://twig.symfony.com/doc/3.x/functions/' + func + '.html#' + func; - - $(this).html(anchor(url, func)); + [...templateCode.querySelectorAll('.hljs-template-variable > .hljs-name')].forEach((elt) => { + const func = elt.textContent; + const url = 'https://twig.symfony.com/doc/3.x/functions/' + func + '.html#' + func; + elt.innerHTML = anchor(url, func); }); }); diff --git a/src/Controller/BlogController.php b/src/Controller/BlogController.php index 6b4711c01..0a8afa60d 100644 --- a/src/Controller/BlogController.php +++ b/src/Controller/BlogController.php @@ -70,7 +70,7 @@ public function index(Request $request, int $page, string $_format, PostReposito * after performing a database query looking for a Post with the 'slug' * value given in the route. * - * See https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html + * See https://symfony.com/doc/current/doctrine.html#automatically-fetching-objects-entityvalueresolver */ #[Route('/posts/{slug}', name: 'blog_post', methods: ['GET'])] public function postShow(Post $post): Response @@ -93,10 +93,10 @@ public function postShow(Post $post): Response } /** - * NOTE: The ParamConverter mapping is required because the route parameter + * NOTE: The #[MapEntity] mapping is required because the route parameter * (postSlug) doesn't match any of the Doctrine entity properties (slug). * - * See https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html#doctrine-converter + * See https://symfony.com/doc/current/doctrine.html#doctrine-entity-value-resolver */ #[Route('/comment/{postSlug}/new', name: 'comment_new', methods: ['POST'])] #[IsGranted('IS_AUTHENTICATED')] @@ -140,7 +140,9 @@ public function commentNew( * a route name for it. * * The "id" of the Post is passed in and then turned into a Post object - * automatically by the ParamConverter. + * automatically by the ValueResolver. + * + * See https://symfony.com/doc/current/doctrine.html#automatically-fetching-objects-entityvalueresolver */ public function commentForm(Post $post): Response {