Skip to content

Instantly share code, notes, and snippets.

@johnrobertwilson
Created November 21, 2011 16:11
Show Gist options
  • Save johnrobertwilson/1383075 to your computer and use it in GitHub Desktop.
Save johnrobertwilson/1383075 to your computer and use it in GitHub Desktop.
Form Alter what?
/**
* Implementation of hook_form_alter
*/
function socialflow_form_alter(&$form, &$form_state, $form_id) {
$socialflow_entities = variable_get('socialflow_entities',array());
//check settings for entity type and bundle
if(array_key_exists('#entity_type', $form) &&
array_key_exists($form['#entity_type'], $socialflow_entities) &&
array_key_exists('#bundle', $form) &&
array_key_exists($form['#bundle'], $socialflow_entities[$form['#entity_type']]) &&
$socialflow_entities[$form['#entity_type']][$form['#bundle']]){
//Add JS for datepicker helper
drupal_add_js('SOCIALFLOW.datePickerHelper.init();', 'inline');
$form['socialflow'] = array(
'#type' => 'fieldset',
'#title'=> 'SocialFlow',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => -4.5,
);
$accounts = variable_get('socialflow_accounts', array());
$accounts_options = array();
foreach ($accounts as $account) {
$name = !empty($account->screen_name) ? $account->screen_name : $account->name;
$accounts_options[$account->service_user_id . ':' . $account->account_type] = $account->account_type . ' : ' . $name;
}
$logo_path = drupal_get_path('module', 'socialflow') . '/socialflow_logo_bw.jpg';
$form['socialflow']['socialflow-logo'] = array(
'#markup' => '<div class="socialflow-logo"><img src="/' . $logo_path . '" /></div>',
);
$form['socialflow']['account'] = array(
'#type' => 'select',
'#title' => t('Social Account'),
'#options' => $accounts_options,
);
$form['socialflow']['socialflow-message'] = array(
'#prefix' => '<div class="socialflow-character-limit">140</div>',
'#type' => 'textarea',
'#title' => t('Message to send'),
'#rows' => 3,
);
$form['socialflow']['status'] = array(
'#type' => 'radios',
'#title' => t('Status'),
'#options' => array('optimize' => 'Optimize', 'publish' => 'Publish Now', 'schedule' => 'Schedule', 'hold' => 'Hold'),
'#default_value' => 'optimize',
'#required' => FALSE,
);
$form['socialflow']['date-and-time'] = array(
'#type' => 'date_popup',
'#title' => 'Optimize from',
'#default_value' => '',
'#date_format' => 'm/d/Y h:i a',
);
$form['socialflow']['end-date'] = array(
'#type' => 'date_popup',
'#title' => 'Optimize to',
'#default_value' => '',
'#date_format' => 'm/d/Y h:i a',
);
if (arg(1) != 'add') {
//Check if entity has been sent to socialflow yet
$history = socialflow_get_history($form['#entity_type'], $form['#bundle'], arg(1));
if (!empty($history)) {
$form['socialflow']['resend'] = array(
'#prefix' => t('Submitted on ' . date('m/d/Y h:m', $history->submitted)),
'#type' => 'checkbox',
'#title' => 'Re-send to socialflow',
'#disabled' => FALSE,
);
}
}
$form['#submit'][] = 'socialflow_node_form_submit_callback';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment