FormSubmitterInterface.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Drupal\Core\Form;
  3. /**
  4. * Provides an interface for processing form submissions.
  5. */
  6. interface FormSubmitterInterface {
  7. /**
  8. * Handles the submitted form, executing callbacks and processing responses.
  9. *
  10. * @param array $form
  11. * An associative array containing the structure of the form.
  12. * @param \Drupal\Core\Form\FormStateInterface $form_state
  13. * The current state of the form.
  14. *
  15. * @return null|\Symfony\Component\HttpFoundation\Response
  16. * If a response was set by a submit handler, or if the form needs to
  17. * redirect, a Response object will be returned.
  18. */
  19. public function doSubmitForm(&$form, FormStateInterface &$form_state);
  20. /**
  21. * Executes custom submission handlers for a given form.
  22. *
  23. * Button-specific handlers are checked first. If none exist, the function
  24. * falls back to form-level handlers.
  25. *
  26. * @param $form
  27. * An associative array containing the structure of the form.
  28. * @param $form_state
  29. * The current state of the form. If the user submitted the form by clicking
  30. * a button with custom handler functions defined, those handlers will be
  31. * stored here.
  32. */
  33. public function executeSubmitHandlers(&$form, FormStateInterface &$form_state);
  34. /**
  35. * Redirects the user to a URL after a form has been processed.
  36. *
  37. * After a form is submitted and processed, normally the user should be
  38. * redirected to a new destination page. This function figures out what that
  39. * destination should be, based on the $form_state and the 'destination'
  40. * query string in the request URL, and redirects the user there.
  41. *
  42. * The result of \Drupal\Core\Form|FormStateInterface::getRedirect()
  43. * determines where to redirect the user. See the possible return values
  44. * listed there. If the result is FALSE, then the user will not be redirected.
  45. *
  46. * Here is an example of how to set up a form to redirect to the path 'user':
  47. * @code
  48. * $form_state->setRedirect('user.page');
  49. * @endcode
  50. * And here is an example of how to redirect to 'node/123?foo=bar#baz':
  51. * @code
  52. * $form_state->setRedirect('entity.node.canonical',
  53. * array('node' => 123),
  54. * array(
  55. * 'query' => array(
  56. * 'foo' => 'bar',
  57. * ),
  58. * 'fragment' => 'baz',
  59. * ),
  60. * );
  61. * @endcode
  62. *
  63. * @param \Drupal\Core\Form\FormStateInterface $form_state
  64. * The current state of the form.
  65. *
  66. * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
  67. *
  68. * @see \Drupal\Core\Form\FormBuilderInterface::processForm()
  69. * @see \Drupal\Core\Form\FormBuilderInterface::buildForm()
  70. */
  71. public function redirectForm(FormStateInterface $form_state);
  72. }