public function ViewsReferenceTrait::massageFormValues in Views Reference Field 8.2
Massages the form values into the format expected for field values.
We need to flatten the options array and serialize the settings for the data attribute.
Parameters
array $values: The submitted form values produced by the widget.
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.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
array An array of field values, keyed by delta.
File
- src/
Plugin/ Field/ FieldWidget/ ViewsReferenceTrait.php, line 372
Class
- ViewsReferenceTrait
- Trait for shared code in Viewsreference Field Widgets.
Namespace
Drupal\viewsreference\Plugin\Field\FieldWidgetCode
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
$values = parent::massageFormValues($values, $form, $form_state);
foreach ($values as $key => $value) {
if (isset($value['options']) && is_array($value['options'])) {
foreach ($value['options'] as $ind => $option) {
$values[$key][$ind] = $option;
}
unset($value['options']);
}
}
// Serialize settings to store them in the data attribute.
$values = $this
->serializeSettingsValues($values);
return $values;
}