You are here

function faqfield_field_widget_form_default_value_element in FAQ Field 7

Element validation handler (field settings page).

Element validation / submission handler for handling default values from the field settings page.

1 string reference to 'faqfield_field_widget_form_default_value_element'
faqfield_field_widget_form in ./faqfield.module
Implements hook_field_widget_form().

File

./faqfield.module, line 605
FAQ Field Provides a field for frequently asked questions.

Code

function faqfield_field_widget_form_default_value_element($element, &$form_state, $form) {
  $field = $form['#field'];

  // As we can set a default format from the field configuration page,
  // we want to save it even if question and answer are actually empty
  // but we have to make sure the submitted default value is saved
  // separately to avoid the widget form beeing build twice (#1526448).
  if (isset($form_state['values'][$field['field_name']])) {

    // Save the default value in the field instance in our own way.
    $default_value = $form_state['values'][$field['field_name']][LANGUAGE_NONE][0];

    // If we're using the formatable answer widget we have to
    // extract the default values (value and format) out of it.
    if (is_array($default_value['answer'])) {
      $default_value['answer_format'] = $default_value['answer']['format'];
      $default_value['answer'] = $default_value['answer']['value'];
    }
    $form_state['values']['instance']['default_values'] = $default_value;
    $form_state['values'][$field['field_name']] = NULL;
  }
}