function tripal_entity_form_submit

3.x TripalEntityUIController.inc tripal_entity_form_submit($form, &$form_state)

Implements hook_submit() for the tripal_entity_form.

1 string reference to 'tripal_entity_form_submit'

File

tripal/includes/TripalEntityUIController.inc, line 627

Code

function tripal_entity_form_submit($form, &$form_state) {
  $entity = $form_state['TripalEntity'];

  if ($form_state['clicked_button']['#name'] == 'cancel_data') {
    if (property_exists($entity, 'id')) {
      $form_state['redirect'] = "bio_data/" . $entity->id;
    }
    else {
      $form_state['redirect'] = 'bio_data/add';
    }
    return;
  }

  if ($form_state['clicked_button']['#name'] == 'delete_data') {
    $form_state['redirect'] = 'bio_data/' . $entity->id . '/delete';
    return;
  }

  $username = $form_state['values']['author_name'];
  $user = user_load_by_name($username);
  $entity->uid = $user->uid;

  $create_date = $form_state['values']['author_date'];
  $entity->created = $create_date;

  $published = $form_state['values']['status'];
  $entity->status = $published;

  // Allow the fields to perform actions prior to submit.
  $instances = field_info_instances('TripalEntity', $entity->bundle);
  $langcode = 'und';
  foreach ($instances as $field_name => $instance) {
    $entity_type = $instance['entity_type'];
    if ($entity_type == 'TripalEntity' and array_key_exists($field_name, $form)) {
      foreach ($form[$field_name][$langcode] as $delta => $field_form) {
        if (!preg_match('/^\d+$/', $delta)) {
          continue;
        }
        $widget_type = $instance['widget']['type'];
        if (tripal_load_include_field_class($widget_type)) {
          $field = $field_form['#field'];
          $widget = new $widget_type($field, $instance);
          $widget->submit($form, $form_state, $entity_type, $entity, $langcode, $delta);
        }
      }
    }
  }

  $entityform = entity_ui_controller('TripalEntity')->entityFormSubmitBuildEntity($form, $form_state);
  if ($entityform->save()) {
    $form_state['redirect'] = "bio_data/" . $entity->id;
  }
  else {
    drupal_set_message('Cannot save entity', 'error');
  }

}