You are here

function mailchimp_activity_entity_form_submit in Mailchimp 7.4

Same name and namespace in other branches
  1. 7.5 modules/mailchimp_activity/includes/mailchimp_activity.admin.inc \mailchimp_activity_entity_form_submit()
  2. 7.2 modules/mailchimp_activity/mailchimp_activity.admin.inc \mailchimp_activity_entity_form_submit()
  3. 7.3 modules/mailchimp_activity/includes/mailchimp_activity.admin.inc \mailchimp_activity_entity_form_submit()

Submit handler for mailchimp_activity_entity_form().

File

modules/mailchimp_activity/includes/mailchimp_activity.admin.inc, line 168
Administration pages for mailchimp_activity module.

Code

function mailchimp_activity_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'];
  $values['entity_path'] = $uri['path'];
  if ($form_state['op'] == 'add' || $form_state['op'] == 'clone') {
    $activity_entity = entity_create('mailchimp_activity_entity', $values);
  }
  else {
    $activity_entity = $form_state['mailchimp_activity_entity'];
    foreach ($values as $key => $val) {
      $activity_entity->{$key} = $val;
    }
  }
  $activity_entity
    ->save();

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