PluginFormInterface.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Drupal\Core\Plugin;
  3. use Drupal\Core\Form\FormStateInterface;
  4. /**
  5. * Provides an interface for an embeddable plugin form.
  6. *
  7. * Plugins can implement this form directly, or a standalone class can be used.
  8. * Decoupled forms can implement \Drupal\Component\Plugin\PluginAwareInterface
  9. * in order to gain access to the plugin.
  10. *
  11. * @ingroup plugin_api
  12. */
  13. interface PluginFormInterface {
  14. /**
  15. * Form constructor.
  16. *
  17. * Plugin forms are embedded in other forms. In order to know where the plugin
  18. * form is located in the parent form, #parents and #array_parents must be
  19. * known, but these are not available during the initial build phase. In order
  20. * to have these properties available when building the plugin form's
  21. * elements, let this method return a form element that has a #process
  22. * callback and build the rest of the form in the callback. By the time the
  23. * callback is executed, the element's #parents and #array_parents properties
  24. * will have been set by the form API. For more documentation on #parents and
  25. * #array_parents, see \Drupal\Core\Render\Element\FormElement.
  26. *
  27. * @param array $form
  28. * An associative array containing the initial structure of the plugin form.
  29. * @param \Drupal\Core\Form\FormStateInterface $form_state
  30. * The current state of the form. Calling code should pass on a subform
  31. * state created through
  32. * \Drupal\Core\Form\SubformState::createForSubform().
  33. *
  34. * @return array
  35. * The form structure.
  36. */
  37. public function buildConfigurationForm(array $form, FormStateInterface $form_state);
  38. /**
  39. * Form validation handler.
  40. *
  41. * @param array $form
  42. * An associative array containing the structure of the plugin form as built
  43. * by static::buildConfigurationForm().
  44. * @param \Drupal\Core\Form\FormStateInterface $form_state
  45. * The current state of the form. Calling code should pass on a subform
  46. * state created through
  47. * \Drupal\Core\Form\SubformState::createForSubform().
  48. */
  49. public function validateConfigurationForm(array &$form, FormStateInterface $form_state);
  50. /**
  51. * Form submission handler.
  52. *
  53. * @param array $form
  54. * An associative array containing the structure of the plugin form as built
  55. * by static::buildConfigurationForm().
  56. * @param \Drupal\Core\Form\FormStateInterface $form_state
  57. * The current state of the form. Calling code should pass on a subform
  58. * state created through
  59. * \Drupal\Core\Form\SubformState::createForSubform().
  60. */
  61. public function submitConfigurationForm(array &$form, FormStateInterface $form_state);
  62. }