Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Field/WidgetBaseInterface.php \Drupal\Core\Field\WidgetBaseInterface
  2. 9 core/lib/Drupal/Core/Field/WidgetBaseInterface.php \Drupal\Core\Field\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\Core\Field\WidgetBase. See Drupal\Core\Field\WidgetInterface for methods that will more likely be overridden in actual widget implementations.

Hierarchy

Expanded class hierarchy of WidgetBaseInterface

All classes that implement WidgetBaseInterface

File

core/lib/Drupal/Core/Field/WidgetBaseInterface.php, line 16

Namespace

Drupal\Core\Field
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\Field\FieldItemListInterface $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 \Drupal\Core\Form\FormStateInterface $form_state
   *   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(FieldItemListInterface $items, array &$form, FormStateInterface $form_state, $get_delta = NULL);

  /**
   * Extracts field values from submitted form values.
   *
   * @param \Drupal\Core\Field\FieldItemListInterface $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 \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   */
  public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state);

  /**
   * Reports field-level validation errors against actual form elements.
   *
   * @param \Drupal\Core\Field\FieldItemListInterface $items
   *   The field values.
   * @param \Symfony\Component\Validator\ConstraintViolationListInterface $violations
   *   A list of constraint violations to flag.
   * @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 \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   */
  public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state);

  /**
   * Retrieves processing information about the widget from $form_state.
   *
   * This method is static so that it can be used in static Form API callbacks.
   *
   * @param array $parents
   *   The array of #parents where the field lives in the form.
   * @param string $field_name
   *   The field name.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   *
   * @return array
   *   An array with the following key/value pairs:
   *   - items_count: The number of widgets to display for the field.
   *   - array_parents: The location of the field's widgets within the $form
   *     structure. This entry is populated at '#after_build' time.
   */
  public static function getWidgetState(array $parents, $field_name, FormStateInterface $form_state);

  /**
   * Stores processing information about the widget in $form_state.
   *
   * This method is static so that it can be used in static Form API #callbacks.
   *
   * @param array $parents
   *   The array of #parents where the widget lives in the form.
   * @param string $field_name
   *   The field name.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   * @param array $field_state
   *   The array of data to store. See getWidgetState() for the structure and
   *   content of the array.
   */
  public static function setWidgetState(array $parents, $field_name, FormStateInterface $form_state, array $field_state);

}

Members

Namesort descending Modifiers Type Description Overrides
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 4
PluginInspectionInterface::getPluginId public function Gets the plugin_id of the plugin instance. 2
PluginSettingsInterface::defaultSettings public static function Defines the default settings for this 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::onDependencyRemoval public function Informs the plugin that some configuration it depends on will be deleted. 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
ThirdPartySettingsInterface::getThirdPartyProviders public function Gets the list of third parties that store information. 3
ThirdPartySettingsInterface::getThirdPartySetting public function Gets the value of a third-party setting. 3
ThirdPartySettingsInterface::getThirdPartySettings public function Gets all third-party settings of a given module. 3
ThirdPartySettingsInterface::setThirdPartySetting public function Sets the value of a third-party setting. 3
ThirdPartySettingsInterface::unsetThirdPartySetting public function Unsets a third-party setting. 3
WidgetBaseInterface::extractFormValues public function Extracts field values from submitted form values. 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::getWidgetState public static function Retrieves processing information about the widget from $form_state. 1
WidgetBaseInterface::setWidgetState public static function Stores processing information about the widget in $form_state. 1