You are here

function search_api_admin_add_server_validate in Search API 7

Form validation handler for adding a server.

Validates the machine name and calls the service class' validation handler.

File

./search_api.admin.inc, line 284
Administration page callbacks for the Search API module.

Code

function search_api_admin_add_server_validate(array $form, array &$form_state) {
  if (!empty($form_state['values']['machine_name'])) {
    $name = $form_state['values']['machine_name'];
    if (is_numeric($name)) {
      form_set_error('machine_name', t('The machine name must not be a pure number.'));
    }
  }
  if (empty($form_state['values']['options']['class'])) {
    return;
  }
  $class = $form_state['values']['options']['class'];
  $info = search_api_get_service_info($class);
  $service = NULL;
  if (class_exists($info['class'])) {
    $service = new $info['class']($form_state['server']);
  }
  if (!$service instanceof SearchApiServiceInterface) {
    form_set_error('class', t('There seems to be something wrong with the selected service class.'));
    return;
  }
  $form_state['values']['options']['service'] = $service;
  if (!empty($form_state['values']['options']['form'])) {
    $service
      ->configurationFormValidate($form['options']['form'], $form_state['values']['options']['form'], $form_state);
  }
}