interface WidgetBaseInterface

Base interface definition for "Field widget" plugins.

This interface details base wrapping methods that most widget implementations will want to directly inherit from Drupal\field\Plugin\Type\Widget\WidgetBase. See Drupal\field\Plugin\Type\Widget\WidgetInterface for methods that will more likely be overriden.

Hierarchy

Expanded class hierarchy of WidgetBaseInterface

All classes that implement WidgetBaseInterface

File

drupal/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBaseInterface.php, line 21
Definition of Drupal\field\Plugin\Type\Widget\WidgetBaseInterface.

Namespace

Drupal\field\Plugin\Type\Widget
View source
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.
   *
   * @param Drupal\Core\Entity\EntityInterface $entity
   *   The entity for which the widget is being built.
   * @param string $langcode
   *   The language associated with the field.
   * @param array $items
   *   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.
   */
  public function form(EntityInterface $entity, $langcode, array $items, array &$form, array &$form_state, $get_delta = NULL);

  /**
   * Extracts field values from submitted form values.
   *
   * @param Drupal\Core\Entity\EntityInterface $entity
   *   The entity for which the widget is being submitted.
   * @param string $langcode
   *   The language associated to $items.
   * @param array $items
   *   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.
   */
  public function submit(EntityInterface $entity, $langcode, array &$items, array $form, array &$form_state);

  /**
   * Reports field-level validation errors against actual form elements.
   *
   * @param Drupal\Core\Entity\EntityInterface $entity
   *   The entity for which the widget is being submitted.
   * @param string $langcode
   *   The language associated to $items.
   * @param array $items
   *   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.
   */
  public function flagErrors(EntityInterface $entity, $langcode, array $items, array $form, array &$form_state);

}

Members

Namesort descending Modifiers Type Description Overrides
PluginInspectionInterface::getDefinition public function Returns the definition of the plugin implementation. 1
PluginInspectionInterface::getPluginId public function Returns the plugin_id of the plugin instance. 1
PluginSettingsInterface::getDefaultSettings public function Returns the default settings for the plugin. 1
PluginSettingsInterface::getSetting public function Returns the value of a setting, or its default value if absent. 1
PluginSettingsInterface::getSettings public function Returns the array of settings, including defaults for missing settings. 1
PluginSettingsInterface::setSetting public function Sets the value of a setting for the plugin. 1
PluginSettingsInterface::setSettings public function Sets the settings for the plugin. 1
WidgetBaseInterface::flagErrors public function Reports field-level validation errors against actual form elements. 1
WidgetBaseInterface::form public function Creates a form element for a field. 1
WidgetBaseInterface::submit public function Extracts field values from submitted form values. 1