function activity_form_submit in Activity 6.2
Form submit controller.
File
- ./
activity.admin.inc, line 97 - activity.admin.inc Contains administrative forms for activity.module
Code
function activity_form_submit($form, &$form_state) {
if (empty($form_state['storage'])) {
$form_state['storage'] = array();
$form_state['storage']['values'] = array();
}
// Call user-defined submit function.
if (!empty($form_state['values']['step_submit'])) {
$function = $form_state['values']['step_submit'];
$function($form, $form_state);
}
// Store submitted form values, this must happen after function call above to
// allow for modifying $form_state['values'].
$this_step = $form_state['values']['this_step'];
$form_state['storage']['values'][$this_step] = $form_state['values'];
// Set up next step.
if (!empty($form_state['values']['step_next']) && $form_state['values']['op'] != 'Back') {
$form_state['storage']['step'] = $form_state['values']['step_next'];
}
else {
if ($form_state['values']['op'] == 'Back') {
// Set up previous step
$form_state['storage']['step'] = $form_state['values']['step_prev'];
}
else {
// Form complete!
$values = $form_state['storage']['values'];
$hook = $values['triggers']['hook'];
$op = $values['operations']['operation'];
$module = activity_module_name($hook);
$info = call_user_func($module . '_activity_info');
foreach (activity_enabled_languages() as $id => $language) {
foreach ($info->objects as $type) {
$params[$type . '-pattern-' . $id] = $values['messages'][$type . '-pattern-' . $id];
}
$params['everyone-pattern-' . $id] = $values['messages']['everyone-pattern-' . $id];
}
$desc = $values['messages']['description'];
$update = TRUE;
if (!($aid = $values['messages']['aid'])) {
$aid = NULL;
$update = FALSE;
}
// handle the types, thanks Checkboxes :-D
foreach ($values['operations']['activity_types'] as $type => $nice_name) {
if (empty($nice_name)) {
unset($values['operations']['activity_types'][$type]);
}
}
$params['activity_types'] = $values['operations']['activity_types'];
// Save the action
include_once 'includes/actions.inc';
// In order to save the aid into the actions.parameters column, when a new
// template is created, the aid must be generated. Can look into using
// {actions_aid} table for this as well. SELECT aid + 1 ORDER BY aid DESC ?
if (!$update) {
$aid = actions_save('activity_record', 'activity', $params, $desc);
}
$params['aid'] = $aid;
$aid = actions_save('activity_record', 'activity', $params, $desc, $aid);
// Save the trigger assignment
// @todo: calc weight (last param)
$record = new stdClass();
$record->hook = $hook;
$record->op = $op;
$record->aid = $aid;
$record->weight = 1;
// try update first
drupal_write_record('trigger_assignments', $record, array(
'aid',
));
if (!db_affected_rows()) {
// ok then insert
drupal_write_record('trigger_assignments', $record);
}
unset($form_state['storage']);
$form_state['redirect'] = 'admin/build/activity';
drupal_set_message('Saved.');
}
}
}