You are here

function bootstrap_tour_form_submit in Bootstrap Tour 7

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

Submit callback for the Bootstrap Tour create/edit form.

File

./bootstrap_tour.module, line 390

Code

function bootstrap_tour_form_submit($form, &$form_state) {
  $vals = $form_state['values'];
  $tour = new stdClass();
  $tour->description = $vals['description'];
  $tour->title = $vals['title'];
  $tour->is_new = empty($vals['name']) || bootstrap_tour_is_default($vals['name']);
  $tour->name = !empty($vals['name']) ? $vals['name'] : bootstrap_tour_generate_machine_name($vals['title']);
  $tour->autorun = $vals['autorun'];
  $tour->roles = implode(',', $vals['roles']);
  $i = 0;
  while (!empty($vals[$i . '_title'])) {
    $tour->steps[] = array(
      'selector' => $vals[$i . '_selector'],
      'path' => $vals[$i . '_path'],
      'placement' => $vals[$i . '_placement'],
      'title' => $vals[$i . '_title'],
      'content' => $vals[$i . '_content']['value'],
      'format' => $vals[$i . '_content']['format'],
    );
    $i++;
  }
  drupal_alter('bootstrap_tour_presave', $tour, $vals);
  if ($tour->is_new) {
    drupal_write_record('bootstrap_tour', $tour);
  }
  else {
    drupal_write_record('bootstrap_tour', $tour, array(
      'name',
    ));
  }
  drupal_set_message('Tour successfully saved.');
  $form_state['redirect'] = 'admin/structure/tours';
}