function acquia_lift_goal_type_create_form_submit in Acquia Lift Connector 7.2
Same name and namespace in other branches
- 7 acquia_lift.admin.unibar.inc \acquia_lift_goal_type_create_form_submit()
Submit handler to create a new goal for a campaign.
1 call to acquia_lift_goal_type_create_form_submit()
- _acquia_lift_personalize_campaign_wizard_goals_single_add in ./
acquia_lift.admin.wizard.inc - Helper submit function to handle saving a new goal.
File
Code
function acquia_lift_goal_type_create_form_submit($form, &$form_state) {
$action_name = $goal_name = '';
$agent_data = $form_state['values']['agent'];
switch ($form_state['values']['goal_type']) {
case 'existing':
$action_name = $form_state['values']['action_name'];
$goal_name = $form['goal']['action_name']['#options'][$action_name];
break;
case 'page':
$plugin = $form_state['values']['actionable_element'];
list($type, $event) = explode('::', $form_state['values']['event'][$plugin]);
$goal_name = $form_state['values']['title'];
$action_name = personalize_generate_machine_name($goal_name, 'visitor_actions_action_name_exists', '_');
$action = array(
'label' => $goal_name,
'machine_name' => $action_name,
'plugin' => $plugin,
'client_side' => $type == 'client' ? 1 : 0,
'identifier' => '',
'event' => $event,
'pages' => $form_state['values']['pages'],
// The data array gets populated with the plugin-specific
// info for the action.
'data' => isset($form_state['values']['options'][$plugin]) ? $form_state['values']['options'][$plugin] : array(),
);
// Allow the plugin to modify the action before saving.
ctools_include('plugins');
if ($class = ctools_plugin_load_class('visitor_actions', 'actionable_element', $action['plugin'], 'handler')) {
$action = call_user_func_array(array(
$class,
'actionPresave',
), array(
$action,
));
}
visitor_actions_save_action($action);
break;
}
try {
if (!empty($action_name)) {
personalize_goal_save($agent_data->machine_name, $action_name, 1);
}
} catch (Exception $e) {
drupal_set_message($e
->getMessage(), 'error');
}
$form_state['acquia_lift']['goal_name'] = $goal_name;
}