WidgetBaseInterface.php 2.75 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Contains \Drupal\Core\Field\WidgetBaseInterface.
6
7
 */

8
namespace Drupal\Core\Field;
9

10
11
use Symfony\Component\Validator\ConstraintViolationListInterface;

12
13
14
15
/**
 * Base interface definition for "Field widget" plugins.
 *
 * This interface details base wrapping methods that most widget implementations
16
17
 * will want to directly inherit from Drupal\Core\Field\WidgetBase.
 * See Drupal\Core\Field\WidgetInterface for methods that will more
18
19
20
21
22
23
24
25
26
27
28
 * likely be overriden.
 */
interface WidgetBaseInterface extends PluginSettingsInterface {

  /**
   * Creates a form element for a field.
   *
   * If the entity associated with the form is new (i.e., $entity->isNew() is
   * TRUE), the 'default value', if any, is pre-populated. Also allows other
   * modules to alter the form element by implementing their own hooks.
   *
29
   * @param \Drupal\Core\Field\FieldItemListInterface $items
30
31
32
33
34
35
36
37
38
39
40
41
42
   *   An array of the field values. When creating a new entity this may be NULL
   *   or an empty array to use default values.
   * @param array $form
   *   An array representing the form that the editing element will be attached
   *   to.
   * @param array $form_state
   *   An array containing the current state of the form.
   * @param int $get_delta
   *   Used to get only a specific delta value of a multiple value field.
   *
   * @return array
   *   The form element array created for this field.
   */
43
  public function form(FieldItemListInterface $items, array &$form, array &$form_state, $get_delta = NULL);
44
45
46
47

  /**
   * Extracts field values from submitted form values.
   *
48
   * @param \Drupal\Core\Field\FieldItemListInterface $items
49
50
51
52
53
54
55
56
   *   The field values. This parameter is altered by reference to receive the
   *   incoming form values.
   * @param array $form
   *   The form structure where field elements are attached to. This might be a
   *   full form structure, or a sub-element of a larger form.
   * @param array $form_state
   *   The form state.
   */
57
  public function extractFormValues(FieldItemListInterface $items, array $form, array &$form_state);
58
59
60
61

  /**
   * Reports field-level validation errors against actual form elements.
   *
62
   * @param \Drupal\Core\Field\FieldItemListInterface $items
63
   *   The field values.
64
65
   * @param \Symfony\Component\Validator\ConstraintViolationListInterface|\Symfony\Component\Validator\ConstraintViolationInterface[] $violations
   *   The constraint violations that were detected.
66
67
68
69
70
71
   * @param array $form
   *   The form structure where field elements are attached to. This might be a
   *   full form structure, or a sub-element of a larger form.
   * @param array $form_state
   *   The form state.
   */
72
  public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, array &$form_state);
73
74

}