You are here

public function FlexiformElementField::configureFormSubmit in Flexiform 7

Overrides FlexiformElement::configureFormSubmit().

Overrides FlexiformElement::configureFormSubmit

File

includes/element/field.element.inc, line 341
Contains FlexiformElementField class.

Class

FlexiformElementField
Class for Field API elements.

Code

public function configureFormSubmit($form, &$form_state, $flexiform) {
  $instance = $form_state['values']['instance'];
  $field = $form_state['values']['field'];

  // Update any field settings that have changed.
  $element_field = $this
    ->getField();
  $field = array_merge($element_field, $field);
  $original_field = field_info_field($instance['field_name']);
  $this->field = $this
    ->diffArrays($field, $original_field);

  // Work out element instance settings. This gets a little complicated as
  // we want to make sure the default value settings work.
  $element_instance = $this
    ->getInstance();
  $instance = array_merge($element_instance, $instance);
  $original_instance = field_read_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']);
  if ($this
    ->checkWidgetBehavior()) {
    if (!$instance['use_default_value_function']) {
      $element = $form['instance']['default_value_widget'];

      // Extract field values.
      $items = array();
      field_default_extract_form_values(NULL, NULL, $element_field, $element_instance, LANGUAGE_NONE, $items, $element, $form_state);
      field_default_submit(NULL, NULL, $element_field, $element_instance, LANGUAGE_NONE, $items, $element, $form_state);
      $instance['default_value'] = $items ? $items : NULL;
    }
    else {
      unset($instance['default_value']);
    }
  }

  // Cast Required to a boolean so it doesn't get erroneously stored.
  $instance['required'] = (bool) $instance['required'];
  $this->instance = $this
    ->diffArrays($instance, $original_instance);
  parent::configureFormSubmit($form, $form_state, $flexiform);
}