You are here

function search_api_admin_overview in Search API 7

Page callback that shows an overview of defined servers and indexes.

See also

search_api_menu()

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

File

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

Code

function search_api_admin_overview() {
  $base_path = drupal_get_path('module', 'search_api') . '/';
  drupal_add_css($base_path . 'search_api.admin.css');
  drupal_add_js($base_path . 'search_api.admin.js');
  $servers = search_api_server_load_multiple(FALSE);
  $indexes = array();

  // When any entity was not normally created in the database, then show status
  // for all.
  $show_config_status = FALSE;
  foreach (search_api_index_load_multiple(FALSE) as $index) {
    $indexes[$index->server][$index->machine_name] = $index;
    if (!$show_config_status && $index->status != ENTITY_CUSTOM) {
      $show_config_status = TRUE;
    }
  }

  // Show disabled servers after enabled ones.
  foreach ($servers as $id => $server) {
    if (!$server->enabled) {
      unset($servers[$id]);
      $servers[$id] = $server;
    }
    if (!$show_config_status && $server->status != ENTITY_CUSTOM) {
      $show_config_status = TRUE;
    }
  }
  $rows = array();
  $t_server = array(
    'data' => t('Server'),
    'colspan' => 2,
  );
  $t_index = t('Index');
  $t_enabled['data'] = array(
    '#theme' => 'image',
    '#path' => $base_path . 'enabled.png',
    '#alt' => t('enabled'),
    '#title' => t('enabled'),
  );
  $t_enabled['class'] = array(
    'search-api-status',
  );
  $t_disabled['data'] = array(
    '#theme' => 'image',
    '#path' => $base_path . 'disabled.png',
    '#alt' => t('disabled'),
    '#title' => t('disabled'),
  );
  $t_disabled['class'] = array(
    'search-api-status',
  );
  $t_enable = t('Enable');
  $pre_server = 'admin/config/search/search_api/server';
  $pre_index = 'admin/config/search/search_api/index';
  $enable = '/enable';
  foreach ($servers as $server) {
    $url = $pre_server . '/' . $server->machine_name;
    $row = array();
    $row[] = $server->enabled ? $t_enabled : $t_disabled;
    if ($show_config_status) {
      $row[] = theme('entity_status', array(
        'status' => $server->status,
      ));
    }
    $row[] = $t_server;
    $row[] = l($server->name, $url);
    $links = array();

    // The "Enable" function has no menu link, since a token is required. We add
    // it as the first link, since it will most likely be the most useful link
    // for a disabled server. (Same for indexes below.)
    if (!$server->enabled) {
      $links[] = array(
        'title' => $t_enable,
        'href' => $url . $enable,
        'query' => array(
          'token' => drupal_get_token($server->machine_name),
        ),
      );
    }
    $links = array_merge($links, menu_contextual_links('search-api-server', $pre_server, array(
      $server->machine_name,
    )));
    $row[] = theme('search_api_dropbutton', array(
      'links' => $links,
    ));
    $rows[] = _search_api_deep_copy($row);
    if (!empty($indexes[$server->machine_name])) {
      foreach ($indexes[$server->machine_name] as $index) {
        $url = $pre_index . '/' . $index->machine_name;
        $row = array();
        $row[] = $index->enabled ? $t_enabled : $t_disabled;
        if ($show_config_status) {
          $row[] = theme('entity_status', array(
            'status' => $index->status,
          ));
        }
        $row[] = ' ';
        $row[] = $t_index;
        $row[] = l($index->name, $url);
        $links = array();
        if (!$index->enabled && $server->enabled) {
          $links[] = array(
            'title' => $t_enable,
            'href' => $url . $enable,
            'query' => array(
              'token' => drupal_get_token($index->machine_name),
            ),
          );
        }
        $links = array_merge($links, menu_contextual_links('search-api-index', $pre_index, array(
          $index->machine_name,
        )));
        $row[] = theme('search_api_dropbutton', array(
          'links' => $links,
        ));
        $rows[] = _search_api_deep_copy($row);
      }
    }
  }
  if (!empty($indexes[''])) {
    foreach ($indexes[''] as $index) {
      $url = $pre_index . '/' . $index->machine_name;
      $row = array();
      $row[] = $t_disabled;
      if ($show_config_status) {
        $row[] = theme('entity_status', array(
          'status' => $index->status,
        ));
      }
      $row[] = array(
        'data' => $t_index,
        'colspan' => 2,
      );
      $row[] = l($index->name, $url);
      $links = menu_contextual_links('search-api-index', $pre_index, array(
        $index->machine_name,
      ));
      $row[] = theme('search_api_dropbutton', array(
        'links' => $links,
      ));
      $rows[] = _search_api_deep_copy($row);
    }
  }
  $header = array();
  $header[] = t('Status');
  if ($show_config_status) {
    $header[] = t('Configuration');
  }
  $header[] = array(
    'data' => t('Type'),
    'colspan' => 2,
  );
  $header[] = t('Name');
  $header[] = array(
    'data' => t('Operations'),
  );
  return array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => array(
      'class' => array(
        'search-api-overview',
      ),
    ),
    '#empty' => t('There are no search servers or indexes defined yet.'),
  );
}