interface WidgetBaseInterface implements PluginSettingsInterface (View source)

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.

Methods

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.

array
form(FieldItemListInterface $items, array $form, FormStateInterface $form_state, int $get_delta = NULL)

Creates a form element for a field.

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.

static 
setWidgetState(array $parents, string $field_name, FormStateInterface $form_state, array $field_state)

Stores processing information about the widget in $form_state.

Details

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

$this setThirdPartySetting(string $module, string $key, mixed $value)

Sets the value of a third-party setting.

Parameters

string $module

The module providing the third-party setting.

string $key

The setting name.

mixed $value

The setting value.

Return Value

$this

mixed getThirdPartySetting(string $module, string $key, mixed $default = NULL)

Gets the value of a third-party setting.

Parameters

string $module

The module providing the third-party setting.

string $key

The setting name.

mixed $default

The default value

Return Value

mixed

The value.

array getThirdPartySettings(string $module)

Gets all third-party settings of a given module.

Parameters

string $module

The module providing the third-party settings.

Return Value

array

An array of key-value pairs.

mixed unsetThirdPartySetting(string $module, string $key)

Unsets a third-party setting.

Parameters

string $module

The module providing the third-party setting.

string $key

The setting name.

Return Value

mixed

The value.

array getThirdPartyProviders()

Gets the list of third parties that store information.

Return Value

array

The list of third parties.

static array defaultSettings()

Defines the default settings for this plugin.

Return Value

array

A list of default settings, keyed by the setting name.

array getSettings()

Returns the array of settings, including defaults for missing settings.

Return Value

array

The array of settings.

mixed getSetting(string $key)

Returns the value of a setting, or its default value if absent.

Parameters

string $key

The setting name.

Return Value

mixed

The setting value.

$this setSettings(array $settings)

Sets the settings for the plugin.

Parameters

array $settings

The array of settings, keyed by setting names. Missing settings will be assigned their default values.

Return Value

$this

$this setSetting(string $key, mixed $value)

Sets the value of a setting for the plugin.

Parameters

string $key

The setting name.

mixed $value

The setting value.

Return Value

$this

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.

Parameters

array $dependencies

An array of dependencies that will be deleted keyed by dependency type. Dependency types are 'config', 'content', 'module' and 'theme'.

Return Value

bool

TRUE if the plugin configuration has changed, FALSE if not.

See also

EntityDisplayBase

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.

Parameters

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.

array $form

An array representing the form that the editing element will be attached to.

FormStateInterface $form_state

The current state of the form.

int $get_delta

Used to get only a specific delta value of a multiple value field.

Return Value

array

The form element array created for this field.

extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state)

Extracts field values from submitted form values.

Parameters

FieldItemListInterface $items

The field values. This parameter is altered by reference to receive the incoming form values.

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.

FormStateInterface $form_state

The form state.

flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state)

Reports field-level validation errors against actual form elements.

Parameters

FieldItemListInterface $items

The field values.

ConstraintViolationListInterface $violations

A list of constraint violations to flag.

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.

FormStateInterface $form_state

The form state.

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.

Parameters

array $parents

The array of #parents where the field lives in the form.

string $field_name

The field name.

FormStateInterface $form_state

The form state.

Return Value

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.

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.

Parameters

array $parents

The array of #parents where the widget lives in the form.

string $field_name

The field name.

FormStateInterface $form_state

The form state.

array $field_state

The array of data to store. See getWidgetState() for the structure and content of the array.