I'm working on a custom module (my_module) which provides some functionality to a specific paragraph type (my_paragraph) created from the user interface. In my routing file, I have the following route definition.
my_module_controller_action:
path: '/node/{node}/my_paragraph/{paragraph}'
defaults:
_controller: '\Drupal\my_module\Controller\MyModuleController::action'
_title: 'page title'
requirements:
_permission: 'access content'
Now I add a new entity reference field (field_paragraph) to the Basic page content type. Using this field I can add my_paragraph along with other paragraph types.
With this set up, I create a basic page, add a piece of my_paragraph, and saved it (/node/123). I can see my custom controller is not called (because now the path is /node/123), but if I go to /node/123/my_paragraph/1, my custom controller is getting called there and I get the output I want.
- What should I do so that my custom controller can be used on /node/123 page?
- If I add /about as path alias of /node/123, how do I achieve the same outcome?
I'm actually refactoring an old custom module I wrote and trying to move away from the hooks approach if possible. One of the main motivations for me by refactoring is I can use one or more services (together with dependency injections) to separate all the possible logics here.