You are here

function search_api_admin_server_view in Search API 7

Page callback: Displays information about a server.

Parameters

SearchApiServer $server: The server to display.

string|null $action: (optional) An action to execute for the server. One of 'enable', 'disable' or 'clear'.

See also

search_api_menu()

1 string reference to 'search_api_admin_server_view'
search_api_menu in ./search_api.module
Implements hook_menu().

File

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

Code

function search_api_admin_server_view(SearchApiServer $server, $action = NULL) {
  if (!empty($action)) {
    if ($action == 'enable') {
      if (isset($_GET['token']) && drupal_valid_token($_GET['token'], $server->machine_name)) {
        if ($server
          ->update(array(
          'enabled' => 1,
        ))) {
          drupal_set_message(t('The server was successfully enabled.'));
        }
        else {
          drupal_set_message(t('The server could not be enabled. Check the logs for details.'), 'error');
        }
        drupal_goto('admin/config/search/search_api/server/' . $server->machine_name);
      }
      else {
        return MENU_ACCESS_DENIED;
      }
    }
    else {
      $ret = drupal_get_form('search_api_admin_confirm', 'server', $action, $server);
      if (!empty($ret['actions'])) {
        return $ret;
      }
    }
  }
  drupal_set_title(search_api_admin_item_title($server));
  $class = search_api_get_service_info($server->class);
  $options = $server
    ->viewSettings();
  $indexes = array();
  foreach (search_api_index_load_multiple(FALSE, array(
    'server' => $server->machine_name,
  )) as $index) {
    if (!$indexes) {
      $indexes['#theme'] = 'links';
      $indexes['#attributes']['class'] = array(
        'inline',
      );
    }
    $indexes['#links'][] = array(
      'title' => $index->name,
      'href' => 'admin/config/search/search_api/index/' . $index->machine_name,
    );
  }
  $render['view'] = array(
    '#theme' => 'search_api_server',
    '#id' => $server->id,
    '#name' => $server->name,
    '#machine_name' => $server->machine_name,
    '#description' => $server->description,
    '#enabled' => $server->enabled,
    '#class_id' => $server->class,
    '#class_name' => $class['name'],
    '#class_description' => $class['description'],
    '#indexes' => $indexes,
    '#options' => $options,
    '#status' => $server->status,
    '#extra' => $server
      ->getExtraInformation(),
  );
  $render['#attached']['css'][] = drupal_get_path('module', 'search_api') . '/search_api.admin.css';
  if ($server->enabled) {
    $render['form'] = drupal_get_form('search_api_server_status_form', $server);
  }
  return $render;
}