FormSubmitterInterface.php 2.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<?php

namespace Drupal\Core\Form;

/**
 * Provides an interface for processing form submissions.
 */
interface FormSubmitterInterface {

  /**
   * Handles the submitted form, executing callbacks and processing responses.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
15 16
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
17 18 19 20 21
   *
   * @return null|\Symfony\Component\HttpFoundation\Response
   *   If a response was set by a submit handler, or if the form needs to
   *   redirect, a Response object will be returned.
   */
22
  public function doSubmitForm(&$form, FormStateInterface &$form_state);
23 24 25 26 27 28 29 30 31 32

  /**
   * Executes custom submission handlers for a given form.
   *
   * Button-specific handlers are checked first. If none exist, the function
   * falls back to form-level handlers.
   *
   * @param $form
   *   An associative array containing the structure of the form.
   * @param $form_state
33 34 35
   *   The current state of the form. If the user submitted the form by clicking
   *   a button with custom handler functions defined, those handlers will be
   *   stored here.
36
   */
37
  public function executeSubmitHandlers(&$form, FormStateInterface &$form_state);
38 39 40 41 42 43

  /**
   * Redirects the user to a URL after a form has been processed.
   *
   * After a form is submitted and processed, normally the user should be
   * redirected to a new destination page. This function figures out what that
44
   * destination should be, based on the $form_state and the 'destination'
45 46
   * query string in the request URL, and redirects the user there.
   *
47 48 49
   * The result of \Drupal\Core\Form|FormStateInterface::getRedirect()
   * determines where to redirect the user. See the possible return values
   * listed there. If the result is FALSE, then the user will not be redirected.
50
   *
51
   * Here is an example of how to set up a form to redirect to the path 'user':
52
   * @code
53
   * $form_state->setRedirect('user.page');
54 55 56
   * @endcode
   * And here is an example of how to redirect to 'node/123?foo=bar#baz':
   * @code
57
   * $form_state->setRedirect('entity.node.canonical',
58
   *   array('node' => 123),
59 60 61 62 63 64
   *   array(
   *     'query' => array(
   *       'foo' => 'bar',
   *     ),
   *     'fragment' => 'baz',
   *   ),
65
   * );
66 67
   * @endcode
   *
68
   * @param \Drupal\Core\Form\FormStateInterface $form_state
69
   *   The current state of the form.
70 71 72 73 74 75
   *
   * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
   *
   * @see \Drupal\Core\Form\FormBuilderInterface::processForm()
   * @see \Drupal\Core\Form\FormBuilderInterface::buildForm()
   */
76
  public function redirectForm(FormStateInterface $form_state);
77 78

}