You are here

protected function ViewsReferenceTrait::serializeSettingsValues in Views Reference Field 8.2

Serialize views reference settings for storage in the data attribute.

Parameters

array $values: The submitted form values produced by the widget.

Return value

array The changed values with a serialized data attribute.

1 call to ViewsReferenceTrait::serializeSettingsValues()
ViewsReferenceTrait::massageFormValues in src/Plugin/Field/FieldWidget/ViewsReferenceTrait.php
Massages the form values into the format expected for field values.

File

src/Plugin/Field/FieldWidget/ViewsReferenceTrait.php, line 396

Class

ViewsReferenceTrait
Trait for shared code in Viewsreference Field Widgets.

Namespace

Drupal\viewsreference\Plugin\Field\FieldWidget

Code

protected function serializeSettingsValues(array $values) {
  $viewsreference_plugin_manager = \Drupal::service('plugin.manager.viewsreference.setting');
  $plugin_definitions = $viewsreference_plugin_manager
    ->getDefinitions();
  foreach ($values as $delta => $value) {
    $serialized_fields = [];
    foreach ($plugin_definitions as $plugin_definition) {
      $serialized_fields[$plugin_definition['id']] = isset($value[$plugin_definition['id']]) ? $value[$plugin_definition['id']] : NULL;
      unset($values[$delta][$plugin_definition['id']]);
    }
    $values[$delta]['data'] = serialize($serialized_fields);
  }
  return $values;
}