PluginFormInterface.php 2.23 KB
Newer Older
1 2
<?php

3
namespace Drupal\Core\Plugin;
4

5 6
use Drupal\Core\Form\FormStateInterface;

7
/**
8
 * Provides an interface for an embeddable plugin form.
9
 *
10 11 12 13
 * Plugins can implement this form directly, or a standalone class can be used.
 * Decoupled forms can implement \Drupal\Component\Plugin\PluginAwareInterface
 * in order to gain access to the plugin.
 *
14
 * @ingroup plugin_api
15
 */
16
interface PluginFormInterface {
17 18 19 20

  /**
   * Form constructor.
   *
21 22 23 24 25 26 27 28
   * Plugin forms are embedded in other forms. In order to know where the plugin
   * form is located in the parent form, #parents and #array_parents must be
   * known, but these are not available during the initial build phase. In order
   * to have these properties available when building the plugin form's
   * elements, let this method return a form element that has a #process
   * callback and build the rest of the form in the callback. By the time the
   * callback is executed, the element's #parents and #array_parents properties
   * will have been set by the form API. For more documentation on #parents and
29
   * #array_parents, see \Drupal\Core\Render\Element\FormElement.
30
   *
31
   * @param array $form
32
   *   An associative array containing the initial structure of the plugin form.
33
   * @param \Drupal\Core\Form\FormStateInterface $form_state
34
   *   The current state of the complete form.
35 36 37 38
   *
   * @return array
   *   The form structure.
   */
39
  public function buildConfigurationForm(array $form, FormStateInterface $form_state);
40 41 42 43 44

  /**
   * Form validation handler.
   *
   * @param array $form
45 46
   *   An associative array containing the structure of the plugin form as built
   *   by static::buildConfigurationForm().
47
   * @param \Drupal\Core\Form\FormStateInterface $form_state
48
   *   The current state of the complete form.
49
   */
50
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state);
51 52 53 54 55

  /**
   * Form submission handler.
   *
   * @param array $form
56 57
   *   An associative array containing the structure of the plugin form as built
   *   by static::buildConfigurationForm().
58
   * @param \Drupal\Core\Form\FormStateInterface $form_state
59
   *   The current state of the complete form.
60
   */
61
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state);
62 63

}