You are here

function tweet_feed_account_form_submit in Tweet Feed 7.2

Same name and namespace in other branches
  1. 7.3 tweet_feed_admin.inc \tweet_feed_account_form_submit()

Submit handler for accounts form

Take the account information and either save it to a new record or update an existing one

File

./tweet_feed_admin.inc, line 233

Code

function tweet_feed_account_form_submit($form, &$form_state) {

  // Get a shortcut for our $form_state['values'] array
  $values = $form_state['values'];

  // Define our array of data provided by the form
  $data = array(
    'account_name' => $values['account_name'],
    'consumer_key' => $values['consumer_key'],
    'consumer_secret' => $values['consumer_secret'],
    'oauth_token' => $values['oauth_token'],
    'oauth_token_secret' => $values['oauth_token_secret'],
  );

  // If aid is empty then we're creating a new record. Otherwise we are updating an
  // existing one and need to call the proper drupal_write_record function accordingly.
  if (!empty($values['aid'])) {
    $data['aid'] = $values['aid'];
    $status = drupal_write_record('tweet_accounts', $data, array(
      'aid',
    ));
  }
  else {
    $status = drupal_write_record('tweet_accounts', $data);
  }

  // Go back to the list of accounts when we are done.
  $form_state['redirect'] = 'admin/config/services/tweet_feed/accounts';

  // Set the status message based on the result we get from writing our record.
  switch ($status) {
    case SAVED_NEW:
      drupal_set_message('New Twitter account has been successfully added.', 'status');
      break;
    case SAVED_UPDATED:
      drupal_set_message('Twitter account has been successfully updated.', 'status');
      break;
    case FALSE:
    default:
      drupal_set_message('The Twitter details provided could not be properly saved to the database.', 'error');
      break;
  }
}