You are here

function finder_admin_edit_submit in Finder 6

Same name and namespace in other branches
  1. 7 includes/finder.admin.inc \finder_admin_edit_submit()

Submit function for admin finder add/edit page.

File

includes/finder.admin.inc, line 492
The finder admin screens.

Code

function finder_admin_edit_submit($form, &$form_state) {
  $values =& $form_state['values'];
  if ($form_state['clicked_button']['#id'] == 'edit-delete') {
    drupal_goto('admin/build/finder/' . $values['finder_id'] . '/delete');
  }
  else {
    $finder = (object) array(
      'finder_id' => $values['finder_id'],
      'base' => $values['base'],
      'title' => $values['title'],
      'description' => $values['description'],
      'path' => $values['path'],
      'block' => $values['block'],
      'settings' => $values['settings'],
    );
    finder_save($finder);
    if (is_array($values['elements'])) {
      foreach ($values['elements'] as $finder_element_id => $value) {
        $finder_element = (object) array(
          'finder_element_id' => $finder_element_id,
          'weight' => $value['weight'],
        );
        finder_element_save($finder_element);
      }
    }
    drupal_set_message(t('The %ft finder was saved.', array(
      '%ft' => $finder->title,
    )));
    menu_rebuild();

    // Clear the finder_find caches for this finder.
    if ($finder->settings['advanced']['cache_finder_find']) {
      $finder = finder_load($finder->finder_id);
      if (!empty($finder->elements)) {
        cache_clear_all('f' . $finder->finder_id . '|', 'cache_finder_find', TRUE);
        foreach ($finder->elements as $element) {
          cache_clear_all('e' . $element->finder_element_id . '|', 'cache_finder_find', TRUE);
        }
        drupal_set_message(t('Cache for the %ft finder was reset.', array(
          '%ft' => $finder->title,
        )));
      }
    }
    if ($values['add_element']) {
      $finder_element = (object) array(
        'finder_id' => $values['finder_id'],
        'element' => $values['add_element'],
      );
      finder_element_save($finder_element);
      $finder_element->title = t('Finder element !1', array(
        '!1' => $finder_element->finder_element_id,
      ));
      finder_element_save($finder_element);
      drupal_set_message(t('A finder element was added.  Configure the element below.'));
      drupal_goto('admin/build/finder/' . $values['finder_id'] . '/edit/' . $finder_element->finder_element_id . '/edit/');
    }
    else {
      drupal_goto('admin/build/finder/' . $values['finder_id'] . '/edit/');
    }
  }
}