1

There seems to be two ways to link a route to a settings form for a module. I'm curious as to whether one is considered a better practice, and why.

_controller: '\Drupal\mymodule\Controller\MyController::myMethod'

or

_form: '\Drupal\mymodule\Form\mySettingsFormFile
2
  • 1
    Without knowing what is in myMethod() this would be the second one. The extra custom controller class only makes sense if you do something in myMethod() the form controller invoked by _form is not able to do.
    – 4uk4
    May 1, 2019 at 20:29
  • Makes sense. Would you mind pasting your comment as an answer, so I can select it? Thanks!
    – JAyenGreen
    May 2, 2019 at 0:41

1 Answer 1

3

Without knowing what is in the controller this would be the second one. The extra custom controller class only makes sense if you do something in myMethod() the form controller invoked by _form is not able to do.

See https://www.drupal.org/node/2117411#fapi-in-route

This integrates the form in a request so that it can receive route parameters and the request itself as well as returning a response if necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.