function acquia_lift_targeting_form in Acquia Lift Connector 7
Form for assigning options or tests to audiences.
Parameters
$agent: A stdClass object representing the agent.
1 string reference to 'acquia_lift_targeting_form'
- acquia_lift_menu in ./
acquia_lift.module - Implements hook_menu().
File
- ./
acquia_lift.admin.inc, line 1288 - acquia_lift.admin.inc Provides functions needed for the admin UI.
Code
function acquia_lift_targeting_form($form, &$form_state, $agent) {
if ($agent->plugin != 'acquia_lift_target') {
drupal_goto('admin/structure/personalize');
}
// Check if we should display the confirm form, if they are reverting changes.
if (isset($form_state['confirm_revert_changes'])) {
return acquia_lift_confirm_revert_changes($form, $form_state, $agent->machine_name);
}
$option_set = acquia_lift_get_option_set_for_targeting($agent->machine_name);
$variation_options = $saved_targeting = array();
$exising_targeting = acquia_lift_get_structure_from_targeting($option_set);
// The settings reflected in the form will either be what is currently running
// or any saved overrides from when this form was last submitted (if the
// review step was never completed to apply them.)
if (!empty($agent->data['lift_targeting'])) {
$saved_targeting = $agent->data['lift_targeting'];
if ($saved_targeting != $exising_targeting) {
$message = t('The targeting settings shown here do not match what is currently running for this campaign.');
$message_type = 'warning';
}
}
else {
if (personalize_agent_get_status($agent->machine_name) != PERSONALIZE_STATUS_NOT_STARTED) {
$message = t('The targeting settings shown here represent what is currently running for this campaign.');
$message_type = 'ok';
}
$saved_targeting = $exising_targeting;
}
if (isset($message)) {
$form['message'] = array(
'#type' => 'markup',
'#markup' => '<div class="acquia-lift-targeting-message acquia-lift-targeting-message-' . $message_type . '">' . $message . '</div>',
'#weight' => -1,
);
}
foreach ($option_set->options as $option) {
$variation_options[$option['option_id']] = $option['option_label'];
}
$form['agent'] = array(
'#type' => 'value',
'#value' => $agent->machine_name,
);
$form['targeting'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
);
foreach (array_keys($saved_targeting) as $audience) {
$form['targeting'][$audience] = array(
'#title' => $audience,
'#type' => 'select',
'#multiple' => TRUE,
'#options' => array(
'' => t('Select...'),
) + $variation_options,
'#default_value' => isset($saved_targeting[$audience]) ? $saved_targeting[$audience] : '',
);
}
$form['actions'] = array(
'#type' => 'actions',
'#tree' => FALSE,
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
$form['actions']['revert_changes'] = array(
'#type' => 'submit',
'#value' => t('Revert changes'),
);
return $form;
}