SubformStateInterface.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Drupal\Core\Form;
  3. /**
  4. * Stores information about the state of a subform.
  5. *
  6. * In the context of Drupal's Form API, a subform is a form definition array
  7. * that will be nested into a "parent" form. For instance:
  8. *
  9. * @code
  10. * $subform = [
  11. * 'method' => [
  12. * '#type' => 'select',
  13. * // …
  14. * ],
  15. * ];
  16. * $form = [
  17. * // …
  18. * 'settings' => $subform,
  19. * ];
  20. * @endcode
  21. *
  22. * All input fields nested under "settings" are then considered part of that
  23. * "subform". The concept is used mostly when the subform is defined by a
  24. * different class (potentially even in a different module) than the parent
  25. * form. This is often the case for plugins: a plugin's buildConfigurationForm()
  26. * would then be handed an instance of this interface as the second parameter.
  27. *
  28. * The benefit of doing this is that the plugin can then just define the form –
  29. * and use the form state – as if it would define a "proper" form, not nested in
  30. * some other form structure. This means that it won't have to know the key(s)
  31. * under which its form structure will be nested – for instance, when retrieving
  32. * the form values during form validation or submission.
  33. *
  34. * Contrary to "proper" forms, subforms don't translate to a <form> tag in the
  35. * HTML response. Instead, they can only be discerned in the HTML code by the
  36. * nesting of the input tags' names.
  37. *
  38. * @see \Drupal\Core\Plugin\PluginFormInterface::buildConfigurationForm()
  39. */
  40. interface SubformStateInterface extends FormStateInterface {
  41. /**
  42. * Gets the complete form state.
  43. *
  44. * @return \Drupal\Core\Form\FormStateInterface
  45. */
  46. public function getCompleteFormState();
  47. }