From 591a9a939ae32747766e569a5370258c4b2f068e Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 8 Feb 2022 07:50:41 +0000 Subject: [PATCH] feat: add controllers section --- README.rst | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/README.rst b/README.rst index 49f514c..ce628c1 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +56,72 @@ After: Drupal\my_module\Service\ExampleService: autowire: true +Controllers +=========== + +Controllers as services +----------------------- + +.. code-block:: yaml + + # my_module.services.yml + + services: + Drupal\my_module\Controller\ExampleController: [] + +Single-action controllers +------------------------- + +Before: + +.. code-block:: yaml + + # my_module.routing.yml + + my_module.example: + path: '/example' + defaults: + _controller: 'Drupal\my_module\Controller\ExampleController::handle' + requirements: + _permission: 'access content' + +.. code-block:: php + + // modules/my_module/src/Controller/ExampleController.php + + class ExampleController { + + public function handle() { + // ... + } + + } + +After: + +.. code-block:: yaml + + # my_module.routing.yml + + my_module.example: + path: '/example' + defaults: + _controller: 'Drupal\my_module\Controller\ExampleController' + requirements: + _permission: 'access content' + +.. code-block:: php + + // modules/my_module/src/Controller/ExampleController.php + + class ExampleController { + + public function __invoke() { + // ... + } + + } + Automated testing =================