Drupal 8  8.0.2
OptionsWidgetBase Class Reference
Inheritance diagram for OptionsWidgetBase:

Public Member Functions

 __construct ($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings)
 
 formElement (FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 
- Public Member Functions inherited from WidgetBase
 __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 WidgetBaseInterface
 flagErrors (FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state)
 

Static Public Member Functions

static validateElement (array $element, FormStateInterface $form_state)
 
- Static Public Member Functions inherited from WidgetBase
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

 getOptions (FieldableEntityInterface $entity)
 
 getSelectedOptions (FieldItemListInterface $items, $delta=0)
 
 supportsGroups ()
 
 sanitizeLabel (&$label)
 
 getEmptyLabel ()
 
- Protected Member Functions inherited from WidgetBase
 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 ()
 

Protected Attributes

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

Additional Inherited Members

- Static Protected Member Functions inherited from WidgetBase
static getWidgetStateParents (array $parents, $field_name)
 

Detailed Description

Base class for the 'options_*' widgets.

Field types willing to enable one or several of the widgets defined in options.module (select, radios/checkboxes, on/off checkbox) need to implement the OptionsProviderInterface to specify the list of options to display in the widgets.

See Also

Constructor & Destructor Documentation

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

{}

Member Function Documentation

formElement ( FieldItemListInterface  $items,
  $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_form_alter() or hook_field_widget_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.

Parameters
\Drupal\Core\Field\FieldItemListInterface$itemsArray of default values for this field.
int$deltaThe order of this item in the array of sub-elements (0, 1, 2, etc.).
array$elementA form element array containing basic properties for the widget:
  • #field_parents: The 'parents' space for the field in the form. Most widgets can simply overlook this property. This identifies the location where the field values are placed within $form_state->getValues(), and is used to access processing information for the field through the getWidgetState() and setWidgetState() methods.
  • #title: The sanitized element label for the field, ready for output.
  • #description: The sanitized element description for the field, ready for output.
  • #required: A Boolean indicating whether the element value is required; for required multiple value fields, only the first widget's values are required.
  • #delta: The order of this item in the array of sub-elements; see $delta above.
array$formThe form structure where widgets are being 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 The form elements for a single widget for this field.
See Also
hook_field_widget_form_alter()
hook_field_widget_WIDGET_TYPE_form_alter()
}

Implements WidgetInterface.

getEmptyLabel ( )
protected

Returns the empty option label to add to the list of options, if any.

Returns
string|NULL Either a label of the empty option, or NULL.

Referenced by OptionsWidgetBase\getOptions().

Here is the caller graph for this function:

getOptions ( FieldableEntityInterface  $entity)
protected

Returns the array of options for the widget.

Parameters
\Drupal\Core\Entity\FieldableEntityInterface$entityThe entity for which to return options.
Returns
array The array of options for the widget.

References Drupal\currentUser(), OptGroup\flattenOptions(), OptionsWidgetBase\getEmptyLabel(), Drupal\moduleHandler(), and OptionsWidgetBase\supportsGroups().

Referenced by OptionsButtonsWidget\formElement(), OptionsSelectWidget\formElement(), and OptionsWidgetBase\getSelectedOptions().

Here is the call graph for this function:

Here is the caller graph for this function:

getSelectedOptions ( FieldItemListInterface  $items,
  $delta = 0 
)
protected

Determines selected options from the incoming field values.

Parameters
\Drupal\Core\Field\FieldItemListInterface$itemsThe field values.
int$delta(optional) The delta of the item to get options for. Defaults to 0.
Returns
array The array of corresponding selected options.

References OptGroup\flattenOptions(), FieldItemListInterface\getEntity(), and OptionsWidgetBase\getOptions().

Referenced by OptionsButtonsWidget\formElement(), and OptionsSelectWidget\formElement().

Here is the call graph for this function:

Here is the caller graph for this function:

sanitizeLabel ( $label)
protected

Sanitizes a string label to display as an option.

Parameters
string$labelThe label to sanitize.

References FieldFilteredMarkup\create().

Here is the call graph for this function:

supportsGroups ( )
protected

Indicates whether the widgets support optgroups.

Returns
bool TRUE if the widget supports optgroups, FALSE otherwise.

Referenced by OptionsWidgetBase\getOptions().

Here is the caller graph for this function:

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

Form validation handler for widget elements.

Parameters
array$elementThe form element.
\Drupal\Core\Form\FormStateInterface$form_stateThe form state.

References FormStateInterface\setError(), FormStateInterface\setValueForElement(), and t().

Here is the call graph for this function:


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