You are here

function field_tools_field_edit_form_submit in Field tools 8

Same name and namespace in other branches
  1. 7 field_tools.admin.inc \field_tools_field_edit_form_submit()

Submit handler for the form for all instances of a field.

See also

field_tools_field_edit_form()

field_tools_field_edit_form_validate()

field_ui_field_edit_form_submit()

File

./field_tools.admin.inc, line 444
NOTICE: THIS FILE IS OBSOLETE. IT IS BEING KEPT UNTIL ALL FUNCTIONALITY IS PORTED TO DRUPAL 8.

Code

function field_tools_field_edit_form_submit($form, &$form_state) {
  $instance = $form_state['values']['instance'];
  $field = $form['#field'];

  // Handle the default value.
  if (isset($form['instance']['default_value_widget'])) {
    $element = $form['instance']['default_value_widget'];

    // Extract field values.
    $items = array();
    field_default_extract_form_values(NULL, NULL, $field, $instance, LANGUAGE_NONE, $items, $element, $form_state);
    field_default_submit(NULL, NULL, $field, $instance, LANGUAGE_NONE, $items, $element, $form_state);
    $instance['default_value'] = $items ? $items : NULL;
  }
  foreach ($field['bundles'] as $entity_type => $bundles) {
    foreach ($bundles as $bundle) {

      // Fake the entity type and bundle into the instance data to save.
      $instance['entity_type'] = $entity_type;
      $instance['bundle'] = $bundle;
      $instance_source = field_read_instance($entity_type, $field['field_name'], $bundle);
      $instance = array_merge($instance_source, $instance);
      field_update_instance($instance);
      \Drupal::messenger()
        ->addMessage(t('Saved %label instance on entity %entity, bundle %bundle', array(
        '%label' => $instance['label'],
        // TODO: labels.
        '%entity' => $entity_type,
        '%bundle' => $bundle,
      )));
    }
  }

  // Redirect the user to the overview page.
  $form_state['redirect'] = 'admin/reports/fields/tools';
}