Drupal 8  8.0.2
WidgetBase Class Reference
Inheritance diagram for WidgetBase:

Public Member Functions

 __construct ($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings)
 
 form (FieldItemListInterface $items, array &$form, FormStateInterface $form_state, $get_delta=NULL)
 
 extractFormValues (FieldItemListInterface $items, array $form, FormStateInterface $form_state)
 
 settingsForm (array $form, FormStateInterface $form_state)
 
 settingsSummary ()
 
 errorElement (array $element, ConstraintViolationInterface $error, array $form, FormStateInterface $form_state)
 
 massageFormValues (array $values, array $form, FormStateInterface $form_state)
 
- Public Member Functions inherited from PluginSettingsBase
 getSettings ()
 
 getSetting ($key)
 
 setSettings (array $settings)
 
 setSetting ($key, $value)
 
 getThirdPartySettings ($module=NULL)
 
 getThirdPartySetting ($module, $key, $default=NULL)
 
 setThirdPartySetting ($module, $key, $value)
 
 unsetThirdPartySetting ($module, $key)
 
 getThirdPartyProviders ()
 
 calculateDependencies ()
 
 onDependencyRemoval (array $dependencies)
 
- Public Member Functions inherited from PluginInspectionInterface
 getPluginId ()
 
 getPluginDefinition ()
 
- Public Member Functions inherited from WidgetInterface
 formElement (FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 
- Public Member Functions inherited from WidgetBaseInterface
 flagErrors (FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state)
 

Static Public Member Functions

static afterBuild (array $element, FormStateInterface $form_state)
 
static addMoreSubmit (array $form, FormStateInterface $form_state)
 
static addMoreAjax (array $form, FormStateInterface $form_state)
 
static getWidgetState (array $parents, $field_name, FormStateInterface $form_state)
 
static setWidgetState (array $parents, $field_name, FormStateInterface $form_state, array $field_state)
 
static isApplicable (FieldDefinitionInterface $field_definition)
 
- Static Public Member Functions inherited from PluginSettingsBase
static defaultSettings ()
 

Protected Member Functions

 formMultipleElements (FieldItemListInterface $items, array &$form, FormStateInterface $form_state)
 
 formSingleElement (FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 
 getFieldSettings ()
 
 getFieldSetting ($setting_name)
 
 handlesMultipleValues ()
 
 isDefaultValueWidget (FormStateInterface $form_state)
 
- Protected Member Functions inherited from PluginSettingsBase
 mergeDefaults ()
 

Static Protected Member Functions

static getWidgetStateParents (array $parents, $field_name)
 

Protected Attributes

 $fieldDefinition
 
 $settings
 
- Protected Attributes inherited from PluginSettingsBase
 $settings = array()
 
 $thirdPartySettings = array()
 
 $defaultSettingsMerged = FALSE
 

Detailed Description

Base class for 'Field widget' plugin implementations.

Constructor & Destructor Documentation

__construct (   $plugin_id,
  $plugin_definition,
FieldDefinitionInterface  $field_definition,
array  $settings,
array  $third_party_settings 
)

Constructs a WidgetBase object.

Parameters
array$plugin_idThe plugin_id for the widget.
mixed$plugin_definitionThe plugin implementation definition.
\Drupal\Core\Field\FieldDefinitionInterface$field_definitionThe definition of the field to which the widget is associated.
array$settingsThe widget settings.
array$third_party_settingsAny third party settings.

Member Function Documentation

static addMoreAjax ( array  $form,
FormStateInterface  $form_state 
)
static

Ajax callback for the "Add another item" button.

This returns the new page content to replace the page content made obsolete by the form submission.

References FieldStorageDefinitionInterface\CARDINALITY_UNLIMITED, FormStateInterface\getTriggeringElement(), and NestedArray\getValue().

Here is the call graph for this function:

static addMoreSubmit ( array  $form,
FormStateInterface  $form_state 
)
static

Submission handler for the "Add another item" button.

References FormStateInterface\getTriggeringElement(), NestedArray\getValue(), and FormStateInterface\setRebuild().

Here is the call graph for this function:

static afterBuild ( array  $element,
FormStateInterface  $form_state 
)
static

After-build handler for field elements in a form.

This stores the final location of the field within the form structure so that flagErrors() can assign validation errors to the right form element.

errorElement ( array  $element,
ConstraintViolationInterface  $error,
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.

Parameters
array$elementAn array containing the form element for the widget, as generated by formElement().
\Symfony\Component\Validator\ConstraintViolationInterface$violationA constraint violation reported during the validation phase.
array$formThe form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
Returns
array|bool The element on which the error should be flagged, or FALSE to completely ignore the violation (use with care!).
}

Implements WidgetInterface.

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

{Extracts field values from submitted form values.

Parameters
\Drupal\Core\Field\FieldItemListInterface$itemsThe field values. This parameter is altered by reference to receive the incoming form values.
array$formThe form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.
\Drupal\Core\Form\FormStateInterface$form_stateThe form state.
}

Implements WidgetBaseInterface.

References FieldItemListInterface\filterEmptyItems(), NestedArray\getValue(), FormStateInterface\getValues(), WidgetBase\handlesMultipleValues(), WidgetBase\massageFormValues(), TypedDataInterface\setValue(), and SortArray\sortByKeyInt().

Here is the call graph for this function:

form ( FieldItemListInterface  $items,
array &  $form,
FormStateInterface  $form_state,
  $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
\Drupal\Core\Field\FieldItemListInterface$itemsAn array of the field values. When creating a new entity this may be NULL or an empty array to use default values.
array$formAn array representing the form that the editing element will be attached to.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
int$get_deltaUsed to get only a specific delta value of a multiple value field.
Returns
array The form element array created for this field.
}

Implements WidgetBaseInterface.

References FieldFilteredMarkup\create(), WidgetBase\formMultipleElements(), WidgetBase\formSingleElement(), Html\getClass(), PluginInspectionInterface\getPluginId(), WidgetBase\handlesMultipleValues(), and Drupal\token().

Here is the call graph for this function:

formMultipleElements ( FieldItemListInterface  $items,
array &  $form,
FormStateInterface  $form_state 
)
protected

Special handling to create form elements for multiple values.

Handles generic features for multiple fields:

  • number of widgets
  • AHAH-'add more' button
  • table display and drag-n-drop value reordering

References ListInterface\appendItem(), FieldStorageDefinitionInterface\CARDINALITY_UNLIMITED, FieldFilteredMarkup\create(), WidgetBase\formSingleElement(), Html\getUniqueId(), FormStateInterface\isProgrammed(), t(), and Drupal\token().

Referenced by WidgetBase\form().

Here is the call graph for this function:

Here is the caller graph for this function:

formSingleElement ( FieldItemListInterface  $items,
  $delta,
array  $element,
array &  $form,
FormStateInterface  $form_state 
)
protected

Generates the form element for a single copy of the widget.

References WidgetInterface\formElement(), FieldItemListInterface\getEntity(), PluginInspectionInterface\getPluginId(), WidgetBase\isDefaultValueWidget(), and Drupal\moduleHandler().

Referenced by WidgetBase\form(), FileWidget\formMultipleElements(), and WidgetBase\formMultipleElements().

Here is the call graph for this function:

Here is the caller graph for this function:

getFieldSettings ( )
protected

Returns the array of field settings.

Returns
array The array of settings.

Referenced by NumberWidget\formElement(), ImageWidget\formElement(), FileWidget\formElement(), and FileWidget\formMultipleElements().

Here is the caller graph for this function:

static getWidgetState ( array  $parents,
  $field_name,
FormStateInterface  $form_state 
)
static

{Retrieves processing information about the widget from $form_state.This method is static so that is can be used in static Form API callbacks.

Parameters
array$parentsThe array of #parents where the field lives in the form.
string$field_nameThe field name.
\Drupal\Core\Form\FormStateInterface$form_stateThe form state.
Returns
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.
}

Implements WidgetBaseInterface.

References FormStateInterface\getStorage(), and NestedArray\getValue().

Here is the call graph for this function:

static getWidgetStateParents ( array  $parents,
  $field_name 
)
staticprotected

Returns the location of processing information within $form_state.

Parameters
array$parentsThe array of #parents where the widget lives in the form.
string$field_nameThe field name.
Returns
array The location of processing information within $form_state.
handlesMultipleValues ( )
protected

Returns whether the widget handles multiple values.

Returns
bool TRUE if a single copy of formElement() can handle multiple field values, FALSE if multiple values require separate copies of formElement().

References PluginInspectionInterface\getPluginDefinition().

Referenced by WidgetBase\extractFormValues(), and WidgetBase\form().

Here is the call graph for this function:

Here is the caller graph for this function:

static isApplicable ( FieldDefinitionInterface  $field_definition)
static

{Returns if the widget can be used for the provided field.

Parameters
\Drupal\Core\Field\FieldDefinitionInterface$field_definitionThe field definition that should be checked.
Returns
bool TRUE if the widget can be used, FALSE otherwise.
}

Implements WidgetInterface.

isDefaultValueWidget ( FormStateInterface  $form_state)
protected

Returns whether the widget used for default value form.

Parameters
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
Returns
bool TRUE if a widget used to input default value, FALSE otherwise.

References FormStateInterface\get().

Referenced by CommentWidget\formElement(), and WidgetBase\formSingleElement().

Here is the call graph for this function:

Here is the caller graph for this function:

massageFormValues ( array  $values,
array  $form,
FormStateInterface  $form_state 
)

{Massages the form values into the format expected for field values.

Parameters
array$valuesThe submitted form values produced by the widget.
  • If the widget does not manage multiple values itself, the array holds the values generated by the multiple copies of the $element generated by the formElement() method, keyed by delta.
  • If the widget manages multiple values, the array holds the values of the form element generated by the formElement() method.
array$formThe form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.
\Drupal\Core\Form\FormStateInterface$form_stateThe form state.
Returns
array An array of field values, keyed by delta.
}

Implements WidgetInterface.

Referenced by WidgetBase\extractFormValues().

Here is the caller graph for this function:

settingsForm ( array  $form,
FormStateInterface  $form_state 
)

{Returns a form to configure settings for the widget.Invoked from to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.

Parameters
array$formThe form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
Returns
array The form definition for the widget settings.
}

Implements WidgetInterface.

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.

Returns
array A short summary of the widget settings.
}

Implements WidgetInterface.

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

{Stores processing information about the widget in $form_state.This method is static so that is can be used in static Form API #callbacks.

Parameters
array$parentsThe array of #parents where the widget lives in the form.
string$field_nameThe field name.
\Drupal\Core\Form\FormStateInterface$form_stateThe form state.
array$field_stateThe array of data to store. See getWidgetState() for the structure and content of the array.
}

Implements WidgetBaseInterface.

References FormStateInterface\getStorage(), and NestedArray\setValue().

Here is the call graph for this function:


The documentation for this class was generated from the following file: