3 namespace Drupal\Core\Field;
5 use Drupal\Core\Form\FormStateInterface;
6 use Symfony\Component\Validator\ConstraintViolationListInterface;
9 * Base interface definition for "Field widget" plugins.
11 * This interface details base wrapping methods that most widget implementations
12 * will want to directly inherit from Drupal\Core\Field\WidgetBase. See
13 * Drupal\Core\Field\WidgetInterface for methods that will more likely be
14 * overridden in actual widget implementations.
16 interface WidgetBaseInterface extends PluginSettingsInterface {
19 * Creates a form element for a field.
21 * If the entity associated with the form is new (i.e., $entity->isNew() is
22 * TRUE), the 'default value', if any, is pre-populated. Also allows other
23 * modules to alter the form element by implementing their own hooks.
25 * @param \Drupal\Core\Field\FieldItemListInterface $items
26 * An array of the field values. When creating a new entity this may be NULL
27 * or an empty array to use default values.
29 * An array representing the form that the editing element will be attached
31 * @param \Drupal\Core\Form\FormStateInterface $form_state
32 * The current state of the form.
33 * @param int $get_delta
34 * Used to get only a specific delta value of a multiple value field.
37 * The form element array created for this field.
39 public function form(FieldItemListInterface $items, array &$form, FormStateInterface $form_state, $get_delta = NULL);
42 * Extracts field values from submitted form values.
44 * @param \Drupal\Core\Field\FieldItemListInterface $items
45 * The field values. This parameter is altered by reference to receive the
46 * incoming form values.
48 * The form structure where field elements are attached to. This might be a
49 * full form structure, or a sub-element of a larger form.
50 * @param \Drupal\Core\Form\FormStateInterface $form_state
53 public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state);
56 * Reports field-level validation errors against actual form elements.
58 * @param \Drupal\Core\Field\FieldItemListInterface $items
60 * @param \Symfony\Component\Validator\ConstraintViolationListInterface $violations
61 * A list of constraint violations to flag.
63 * The form structure where field elements are attached to. This might be a
64 * full form structure, or a sub-element of a larger form.
65 * @param \Drupal\Core\Form\FormStateInterface $form_state
68 public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state);
71 * Retrieves processing information about the widget from $form_state.
73 * This method is static so that it can be used in static Form API callbacks.
75 * @param array $parents
76 * The array of #parents where the field lives in the form.
77 * @param string $field_name
79 * @param \Drupal\Core\Form\FormStateInterface $form_state
83 * An array with the following key/value pairs:
84 * - items_count: The number of widgets to display for the field.
85 * - array_parents: The location of the field's widgets within the $form
86 * structure. This entry is populated at '#after_build' time.
88 public static function getWidgetState(array $parents, $field_name, FormStateInterface $form_state);
91 * Stores processing information about the widget in $form_state.
93 * This method is static so that it can be used in static Form API #callbacks.
95 * @param array $parents
96 * The array of #parents where the widget lives in the form.
97 * @param string $field_name
99 * @param \Drupal\Core\Form\FormStateInterface $form_state
101 * @param array $field_state
102 * The array of data to store. See getWidgetState() for the structure and
103 * content of the array.
105 public static function setWidgetState(array $parents, $field_name, FormStateInterface $form_state, array $field_state);