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

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

8
namespace Drupal\Core\Field;
9

10
use Drupal\Core\Entity\Field\FieldItemListInterface;
11 12 13 14 15 16
use Drupal\field\Plugin\PluginSettingsInterface;

/**
 * Base interface definition for "Field widget" plugins.
 *
 * This interface details base wrapping methods that most widget implementations
17 18
 * will want to directly inherit from Drupal\Core\Field\WidgetBase.
 * See Drupal\Core\Field\WidgetInterface for methods that will more
19 20 21 22 23 24 25 26 27 28 29
 * 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.
   *
30
   * @param \Drupal\Core\Entity\Field\FieldItemListInterface $items
31 32 33 34 35 36 37 38 39 40 41 42 43
   *   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.
   */
44
  public function form(FieldItemListInterface $items, array &$form, array &$form_state, $get_delta = NULL);
45 46 47 48

  /**
   * Extracts field values from submitted form values.
   *
49
   * @param \Drupal\Core\Entity\Field\FieldItemListInterface $items
50 51 52 53 54 55 56 57
   *   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.
   */
58
  public function extractFormValues(FieldItemListInterface $items, array $form, array &$form_state);
59 60 61 62

  /**
   * Reports field-level validation errors against actual form elements.
   *
63
   * @param \Drupal\Core\Entity\Field\FieldItemListInterface $items
64 65 66 67 68 69 70
   *   The field 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.
   */
71
  public function flagErrors(FieldItemListInterface $items, array $form, array &$form_state);
72 73

}