You are here

function search_config_validate in Search configuration 6

Same name and namespace in other branches
  1. 5 search_config.module \search_config_validate()
1 string reference to 'search_config_validate'
search_config_form_alter in ./search_config.module
Implementation of hook_form_alter()

File

./search_config.module, line 297
Used to configure the advanced search form and other search behaviour.

Code

function search_config_validate($form, &$form_state) {
  if ($form_state['values']['form_id'] == 'search_admin_settings' && $form_state['values']['op'] == t('Save configuration')) {
    $post_values = $form_state['values'];
    $node_types = node_get_types('names');
    if (!isset($post_values['search_config_disable_index_type'])) {
      return;
    }
    $index_types = array_filter($post_values['search_config_disable_index_type']);
    if (!isset($post_values['search_config_disable_type'])) {
      $post_values['search_config_disable_type'] = array();
    }
    $form_types = array_filter($post_values['search_config_disable_type']);
    if (count($index_types) != 0 && count($index_types) == count($node_types)) {
      form_set_error('search_config_disable_index_type', t('You can not set all node types to be not indexed by the search module. Disable the search module if that is what you want.'));
    }
    if ($form_types['all']) {
      return;
    }
    $type_diff = array_diff($index_types, $form_types);
    if (count($type_diff)) {
      $node_errors = array();
      foreach ($type_diff as $type) {
        $node_errors[] = $node_types[$type];
      }
      form_set_error('search_config_disable_type', t('Search index node types do not match form node types. Please check the setting for %nodes.', array(
        '%nodes' => implode(', ', $node_errors),
      )));
    }
  }
}