You are here

function finder_ui_form_submit in Finder 7.2

Form submit callback for finder_ui plugin.

1 string reference to 'finder_ui_form_submit'
finder_ui.inc in modules/finder_ui/plugins/export_ui/finder_ui.inc

File

modules/finder_ui/includes/finder.inc, line 162

Code

function finder_ui_form_submit(&$form, &$form_state) {
  ctools_include('object-cache');
  $finder =& $form_state['item'];
  if (!finder_ui_check_lock($finder)) {
    return;
  }
  if ($form_state['triggering_element']['#parents'][0] == 'cancel') {
    ctools_object_cache_clear('finder', $finder->name);
    drupal_goto('admin/structure/finder');
  }
  $finder
    ->build_elements();
  $finder
    ->defaults();

  // Expand view:display into views_view and views_display.
  if (isset($form_state['values']['view'])) {
    list($view, $display) = explode(':', $form_state['values']['view']);
    $finder->title = $form_state['values']['title'];
    $finder->name = $form_state['values']['name'];
    $finder->description = $form_state['values']['description'];
    $finder->views_view = $view;
    $finder->views_display = $display;
    finder_save($finder);
    ctools_object_cache_set('finder', $finder->name, $finder);
    drupal_goto('admin/structure/finder/list/' . $finder->name);
  }
  else {
    $finder = ctools_object_cache_get('finder', $finder->name);
    if (isset($form_state['values']['admin']['admin']['columns'][3]['elements']['items']['elements']['elements'])) {
      $tabledrags = $form_state['values']['admin']['admin']['columns'][3]['elements']['items']['elements']['elements'];
      foreach ($tabledrags as $feid => $tabledrag) {
        $element =& $finder->elements[$feid];
        $element->weight = $tabledrag['weight'];
        $element->parent = $tabledrag['parent'];
      }
      $finder
        ->element_weights();
    }
    $validate = $finder
      ->validate();
    if (is_array($validate)) {

      // Validation failed.  Set errors and redirect to form.
      foreach ($validate as $error) {
        drupal_set_message($error, 'error');
      }
      drupal_goto($_GET['q']);
    }
    $form_state['values'] = (array) unserialize(serialize($finder));
    $elements = $form_state['values']['elements'];
    unset($form_state['values']['elements']);
    foreach ($elements as $key => $element) {
      $form_state['values']['elements'][$key] = new stdClass();
      $save_keys = array(
        'id',
        'description',
        'finder',
        'element',
        'title',
        'weight',
        'parent',
        'settings',
      );
      foreach ($element as $k => $v) {
        if (in_array($k, $save_keys)) {
          $form_state['values']['elements'][$key]->{$k} = $v;
        }
      }
    }
  }
  ctools_object_cache_clear('finder', $finder->name);
}