You are here

function mailchimp_automations_entity_form_submit in Mailchimp 7.4

Same name and namespace in other branches
  1. 7.5 modules/mailchimp_automations/includes/mailchimp_automations.admin.inc \mailchimp_automations_entity_form_submit()

Submit handler for mailchimp_automations_entity_form().

File

modules/mailchimp_automations/includes/mailchimp_automations.admin.inc, line 270
Administration pages for mailchimp_automations module.

Code

function mailchimp_automations_entity_form_submit($form, &$form_state) {
  $dummy_entity = entity_create($form_state['values']['entity_type'], array(
    'type' => $form_state['values']['bundle'],
  ));
  $entity_info = entity_get_info($dummy_entity->type);
  if (!empty($entity_info)) {

    // Create empty entity ID field so entity_uri doesn't result in an error.
    $entity_id_field = $entity_info['entity keys']['id'];
    $dummy_entity->{$entity_id_field} = NULL;
  }
  $uri = entity_uri($form_state['values']['entity_type'], $dummy_entity);
  $values = $form_state['values'];
  if ($form_state['op'] == 'add' || $form_state['op'] == 'clone') {
    $automation_entity = entity_create('mailchimp_automations_entity', $values);
  }
  else {
    $automation_entity = $form_state['mailchimp_automations_entity'];
    foreach ($values as $key => $val) {
      $automation_entity->{$key} = $val;
    }
  }
  $automation_entity
    ->save();

  // Make sure the new items appear in the menus:
  menu_rebuild();
  $form_state['redirect'] = 'admin/config/services/mailchimp/automations';
}