You are here

function bootstrap_tour_form in Bootstrap Tour 7

Same name and namespace in other branches
  1. 7.2 includes/bootstrap_tour.admin.inc \bootstrap_tour_form()

Form callback for the administration of site tours.

1 string reference to 'bootstrap_tour_form'
bootstrap_tour_menu in ./bootstrap_tour.module
Implementation of hook_menu()

File

./bootstrap_tour.module, line 258

Code

function bootstrap_tour_form($form, &$form_state, $tour = '') {
  if (!empty($tour)) {
    if (!empty($tour->steps) && !is_array($tour->steps)) {
      $tour->steps = unserialize($tour->steps);
    }
  }
  else {
    $tour = new stdClass();
  }
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#description' => t('A human readable name for this site tour.'),
    '#required' => TRUE,
    '#default_value' => !empty($tour->title) ? $tour->title : '',
  );
  $form['name'] = array(
    '#type' => 'value',
    '#value' => !empty($tour->name) ? $tour->name : '',
  );
  $form['description'] = array(
    '#type' => 'textfield',
    '#title' => t('Description'),
    '#description' => t('Used for administrative purposes only.'),
    '#default_value' => !empty($tour->description) ? $tour->description : '',
  );
  $form['roles'] = array(
    '#type' => 'select',
    '#title' => t('Roles'),
    '#description' => t('Which roles can access this tour? Leave blank for all.'),
    '#multiple' => TRUE,
    '#options' => user_roles(),
    '#default_value' => !empty($tour->roles) ? explode(',', $tour->roles) : '',
  );
  $form['autorun'] = array(
    '#type' => 'checkbox',
    '#title' => t('Automatically run'),
    '#description' => t('Should this tour start automatically the first time a user visits the path of the first step? If this is checked, the first step must have the "Path" field filled out.'),
    '#default_value' => !empty($tour->autorun) ? $tour->autorun : '',
    '#weight' => 5,
  );
  $form['steps_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Tour steps'),
    '#prefix' => '<div id="steps-fieldset-wrapper">',
    '#suffix' => '</div>',
    '#weight' => 10,
  );
  if (empty($form_state['num_steps'])) {
    if (empty($tour->steps)) {
      $form_state['num_steps'] = 1;
    }
    else {
      $form_state['num_steps'] = count($tour->steps);
    }
  }
  for ($i = 0; $i < $form_state['num_steps']; $i++) {
    $form['steps_fieldset'][$i . '_path'] = array(
      '#type' => 'textfield',
      '#title' => t('Path'),
      '#required' => $i == 0,
      '#description' => t('Which path should this step be displayed on? This is required on the first step, but if subsequent steps will use the same path as the previous step(s) you can leave this blank. Enter &lt;front&gt; for the front page.'),
      '#default_value' => !empty($tour->steps[$i]['path']) ? $tour->steps[$i]['path'] : '',
    );
    $form['steps_fieldset'][$i . '_selector'] = array(
      '#type' => 'textfield',
      '#title' => t('CSS Selector'),
      '#description' => t('Leave this blank if you want this popup to show up centered on the page and not attached to a specific element.'),
      '#default_value' => !empty($tour->steps[$i]['selector']) ? $tour->steps[$i]['selector'] : '',
    );
    $form['steps_fieldset'][$i . '_placement'] = array(
      '#type' => 'select',
      '#title' => t('Placement'),
      '#options' => array(
        'top' => t('Top'),
        'bottom' => t('Bottom'),
        'left' => t('Left'),
        'right' => t('Right'),
      ),
      '#default_value' => !empty($tour->steps[$i]['placement']) ? $tour->steps[$i]['placement'] : '',
    );
    $form['steps_fieldset'][$i . '_title'] = array(
      '#type' => 'textfield',
      '#title' => t('Popup Title'),
      '#required' => TRUE,
      '#default_value' => !empty($tour->steps[$i]['title']) ? $tour->steps[$i]['title'] : '',
    );
    $form['steps_fieldset'][$i . '_content'] = array(
      '#type' => 'text_format',
      '#base_type' => 'textarea',
      '#suffix' => '<hr />',
      '#title' => t('Popup Content'),
      '#default_value' => !empty($tour->steps[$i]['content']) ? $tour->steps[$i]['content'] : '',
    );
  }
  $form['add_step'] = array(
    '#type' => 'submit',
    '#value' => t('Add another step'),
    '#submit' => array(
      'bootstrap_tour_form_add_one',
    ),
    '#ajax' => array(
      'callback' => 'bootstrap_tour_form_add_one_callback',
      'wrapper' => 'steps-fieldset-wrapper',
    ),
    '#suffix' => ' ',
    '#weight' => 20,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 20,
  );
  return $form;
}