function abjs_experience_form in A/B Test JS 7
Generates form for creating and editing experiences.
Arg. $eid will be NULL when adding an experience, and will be a number when editing experiences. $eid is checked throughout the function for determining if this is an add form or edit form.
1 string reference to 'abjs_experience_form'
- abjs_menu in ./
abjs.module - Implements hook_menu().
File
- ./
abjs.admin.inc, line 811 - Admin forms to view/add/edit/delete tests, conditions, experiences.
Code
function abjs_experience_form($form, &$form_state, $eid = NULL) {
$form = array();
$experience_name_default = "";
$experience_script_default = "";
if (!empty($eid)) {
$experience_result = db_query('SELECT name, script FROM {abjs_experience} WHERE eid = :eid', array(
':eid' => $eid,
));
if (empty($experience_result)) {
drupal_set_message(t('The requested experience does not exist.'), 'error');
return $form;
}
$experience = $experience_result
->fetchObject();
$experience_name_default = $experience->name;
$experience_script_default = $experience->script;
$form['eid'] = array(
'#type' => 'value',
'#value' => $eid,
);
}
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Experience Name'),
'#default_value' => $experience_name_default,
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE,
);
$form['script'] = array(
'#type' => 'textarea',
'#title' => t('Experience Script'),
'#default_value' => $experience_script_default,
'#description' => t('Any valid javascript to load in head. Leave empty for a Control. Read the <a href="@documentation">documentation</a> for examples', array(
'@documentation' => 'https://www.drupal.org/node/2716391#example-experiences',
)),
'#rows' => 3,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 5,
'#submit' => array(
'abjs_experience_form_save_submit',
),
);
$form['actions']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#weight' => 10,
'#submit' => array(
'abjs_experience_form_cancel_submit',
),
'#limit_validation_errors' => array(),
);
if (!empty($eid)) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#weight' => 15,
'#submit' => array(
'abjs_experience_form_delete_submit',
),
);
}
// Add ace code editor for syntax highlighting on the script field.
if (variable_get('abjs_ace') == 1) {
drupal_add_js('https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.0/ace.js', array(
'type' => 'external',
'scope' => 'header',
'group' => JS_LIBRARY,
));
drupal_add_js(drupal_get_path('module', 'abjs') . '/js/abjs-ace-edit.js', array(
'type' => 'file',
'scope' => 'footer',
'group' => JS_THEME,
));
}
return $form;
}