WidgetInterface
interface WidgetInterface implements WidgetBaseInterface (View source)
Interface definition for field widget plugins.
This interface details the methods that most plugin implementations will want to override. See Drupal\Core\Field\WidgetBaseInterface for base wrapping methods that should most likely be inherited directly from Drupal\Core\Field\WidgetBase..
Methods
Gets the definition of the plugin implementation.
Sets the value of a third-party setting.
Gets the value of a third-party setting.
Gets all third-party settings of a given module.
Unsets a third-party setting.
Gets the list of third parties that store information.
Defines the default settings for this plugin.
Returns the array of settings, including defaults for missing settings.
Returns the value of a setting, or its default value if absent.
Sets the value of a setting for the plugin.
Informs the plugin that some configuration it depends on will be deleted.
Creates a form element for a field.
Extracts field values from submitted form values.
Reports field-level validation errors against actual form elements.
Retrieves processing information about the widget from $form_state.
Stores processing information about the widget in $form_state.
Returns a form to configure settings for the widget.
Returns a short summary for the current widget settings.
Returns the form for a single field widget.
Assigns a field-level validation error to the right widget sub-element.
Massages the form values into the format expected for field values.
Returns if the widget can be used for the provided field.
Details
string
getPluginId()
Gets the plugin_id of the plugin instance.
array
getPluginDefinition()
Gets the definition of the plugin implementation.
$this
setThirdPartySetting(string $module, string $key, mixed $value)
Sets the value of a third-party setting.
mixed
getThirdPartySetting(string $module, string $key, mixed $default = NULL)
Gets the value of a third-party setting.
array
getThirdPartySettings(string $module)
Gets all third-party settings of a given module.
mixed
unsetThirdPartySetting(string $module, string $key)
Unsets a third-party setting.
array
getThirdPartyProviders()
Gets the list of third parties that store information.
static array
defaultSettings()
Defines the default settings for this plugin.
array
getSettings()
Returns the array of settings, including defaults for missing settings.
mixed
getSetting(string $key)
Returns the value of a setting, or its default value if absent.
$this
setSettings(array $settings)
Sets the settings for the plugin.
$this
setSetting(string $key, mixed $value)
Sets the value of a setting for the plugin.
bool
onDependencyRemoval(array $dependencies)
Informs the plugin that some configuration it depends on will be deleted.
This method allows plugins to keep their configuration up-to-date when a dependency calculated with ::calculateDependencies() is removed. For example, an entity view display contains a formatter having a setting pointing to an arbitrary config entity. When that config entity is deleted, this method is called by the view display to react to the dependency removal by updating its configuration.
This method must return TRUE if the removal event updated the plugin configuration or FALSE otherwise.
array
form(FieldItemListInterface $items, array $form, FormStateInterface $form_state, int $get_delta = NULL)
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.
extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state)
Extracts field values from submitted form values.
flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state)
Reports field-level validation errors against actual form elements.
static array
getWidgetState(array $parents, string $field_name, 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.
static
setWidgetState(array $parents, string $field_name, FormStateInterface $form_state, array $field_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.
array
settingsForm(array $form, FormStateInterface $form_state)
Returns a form to configure settings for the widget.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.
array
settingsSummary()
Returns a short summary for the current widget settings.
If an empty result is returned, a UI can still be provided to display a settings form in case the widget has configurable settings.
array
formElement(FieldItemListInterface $items, int $delta, array $element, array $form, FormStateInterface $form_state)
Returns the form for a single field widget.
Field widget form elements should be based on the passed-in $element, which contains the base form element properties derived from the field configuration.
The BaseWidget methods will set the weight, field name and delta values for each form element. If there are multiple values for this field, the formElement() method will be called as many times as needed.
Other modules may alter the form element provided by this function using hook_field_widget_single_element_form_alter() or hook_field_widget_single_element_WIDGET_TYPE_form_alter().
The FAPI element callbacks (such as #process, #element_validate,
value_callback, etc.) used by the widget do not have access to the
original $field_definition passed to the widget's constructor. Therefore, if any information is needed from that definition by those callbacks, the widget implementing this method, or a hook_field_widget[_WIDGET_TYPE]_form_alter() implementation, must extract the needed properties from the field definition and set them as ad-hoc $element['#custom'] properties, for later use by its element callbacks.
array|bool
errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state)
Assigns a field-level validation error to the right widget sub-element.
Depending on the widget's internal structure, a field-level validation error needs to be flagged on the right sub-element.
array
massageFormValues(array $values, array $form, FormStateInterface $form_state)
Massages the form values into the format expected for field values.
static bool
isApplicable(FieldDefinitionInterface $field_definition)
Returns if the widget can be used for the provided field.