From 11f424fe2e18552b43f8aec7c68b2a570c32bbb2 Mon Sep 17 00:00:00 2001 From: Andreas Schempp Date: Wed, 15 Jan 2020 19:01:58 +0100 Subject: [PATCH 1/3] Fix back end route controller example --- docs/dev/guides/backend-routes.md | 40 ++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/docs/dev/guides/backend-routes.md b/docs/dev/guides/backend-routes.md index ee119f717..0d1aa9f4f 100644 --- a/docs/dev/guides/backend-routes.md +++ b/docs/dev/guides/backend-routes.md @@ -26,27 +26,39 @@ and is configured through annotations. // src/Controller/BackendController.php namespace App\Controller; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Response; +use Twig\Environment as TwigEnvironment; /** - * @Route("/contao", defaults={ - * "_scope" = "backend", - * "_token_check" = true, - * "_backend_module" = "my-modules" - * }) + * @Route("/contao//my-backend-route", + * name="app.backend-route" + * defaults={ + * "_scope" = "backend", + * "_token_check" = true, + * "_backend_module" = "my-modules" + * } + * ) */ class BackendController extends AbstractController { + private $twig; + + public function __construct(TwigEnvironment $twig) + { + $this->twig = $twig; + } + /** - * @Route("/my-backend-route", name="app.backend-route") - * @Template("my_backend_route.html.twig") + * @Route("", name="app.backend-route") */ - public function backendRouteAction() + public function __invoke() { - return []; + return new Response($this->twig->render( + 'my_backend_route.html.twig', + [] + )); } } ``` @@ -61,8 +73,8 @@ you need to set this to true, in order to get it to work. the current route in order to highlight the currently active node in the back end menu. More on this later. -Be sure to have imported your bundles Controllers in your `routing.yml` *before* -the `ContaoCoreBundle` routes. +Be sure to have imported your bundles Controllers in your `routing.yml` *before* +the `ContaoCoreBundle` routes. ```yaml # config/routing.yml @@ -92,7 +104,7 @@ which must be placed into `/templates`. {% endblock %} ``` -As we extend from `@ContaoCore/Backend/be_page.html.twig` it is worth noting +As we extend from `@ContaoCore/Backend/be_page.html.twig` it is worth noting that there are three different blocks you can currently use: * `headline`: This block renders the headline of the document. From 77a32c0b5aba3e401650a411c0c3bae3224cc6ba Mon Sep 17 00:00:00 2001 From: Andreas Schempp Date: Thu, 16 Jan 2020 11:04:18 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-Authored-By: Fritz Michael Gschwantner --- docs/dev/guides/backend-routes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/dev/guides/backend-routes.md b/docs/dev/guides/backend-routes.md index 0d1aa9f4f..2d4777c69 100644 --- a/docs/dev/guides/backend-routes.md +++ b/docs/dev/guides/backend-routes.md @@ -32,12 +32,12 @@ use Symfony\Component\HttpFoundation\Response; use Twig\Environment as TwigEnvironment; /** - * @Route("/contao//my-backend-route", + * @Route("/contao/my-backend-route", * name="app.backend-route" * defaults={ * "_scope" = "backend", * "_token_check" = true, - * "_backend_module" = "my-modules" + * "_backend_module" = "my-module" * } * ) */ From 3be88c0789752f6c227b0db6cf3931f904bf841c Mon Sep 17 00:00:00 2001 From: Fritz Michael Gschwantner Date: Wed, 4 Mar 2020 16:25:15 +0100 Subject: [PATCH 3/3] change route name and remove superfluous annotation --- docs/dev/guides/backend-routes.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/dev/guides/backend-routes.md b/docs/dev/guides/backend-routes.md index 2d4777c69..0697da047 100644 --- a/docs/dev/guides/backend-routes.md +++ b/docs/dev/guides/backend-routes.md @@ -33,7 +33,7 @@ use Twig\Environment as TwigEnvironment; /** * @Route("/contao/my-backend-route", - * name="app.backend-route" + * name=App\Controller\BackendController::class * defaults={ * "_scope" = "backend", * "_token_check" = true, @@ -49,10 +49,7 @@ class BackendController extends AbstractController { $this->twig = $twig; } - - /** - * @Route("", name="app.backend-route") - */ + public function __invoke() { return new Response($this->twig->render( @@ -78,7 +75,7 @@ the `ContaoCoreBundle` routes. ```yaml # config/routing.yml -app: +app.controller: resource: ../src/Controller type: annotation ```