function EntityReference::alternateWidgetsDefaultNormalize
Normalize values for widget switching.
The saved values can differ in live preview if switching back and forth between the select and autocomplete widgets. This normalizes the values to avoid errors when making the switch.
Parameters
array $form: Associative array containing the structure of the form, passed by reference.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
1 call to EntityReference::alternateWidgetsDefaultNormalize()
- EntityReference::valueForm in core/
modules/ views/ src/ Plugin/ views/ filter/ EntityReference.php - Options form subform for setting options.
File
-
core/
modules/ views/ src/ Plugin/ views/ filter/ EntityReference.php, line 388
Class
- EntityReference
- Filters a view by entity references.
Namespace
Drupal\views\Plugin\views\filterCode
protected function alternateWidgetsDefaultNormalize(array &$form, FormStateInterface $form_state) : void {
$field_id = '_' . $this->getFieldDefinition()
->getName() . '-widget';
$form[$field_id] = [
'#type' => 'hidden',
'#value' => $this->options['widget'],
];
$previous_widget = $form_state->getUserInput()[$field_id] ?? NULL;
if ($previous_widget && $previous_widget !== $this->options['widget']) {
$form['value']['#value_callback'] = function ($element) {
return $element['#default_value'] ?? '';
};
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.