You are here

function theme_search_api_index in Search API 7

Returns HTML for a search index.

Parameters

array $variables: An associative array containing:

  • id: The index's id.
  • name: The index' name.
  • machine_name: The index' machine name.
  • description: The index' description.
  • item_type: The type of items stored in this index.
  • datasource_config: A summary of the datasource's configuration.
  • enabled: Boolean indicating whether the index is enabled.
  • server: The server this index currently rests on, if any.
  • options: The index' options, like cron limit.
  • fields: All indexed fields of the index.
  • indexed_items: The number of items already indexed in their latest version on this index.
  • on_server: The number of items actually indexed on the server. NULL if the search for finding out the item count failed.
  • total_items: The total number of items that have to be indexed for this index.
  • status: The entity configuration status (in database, in code, etc.).
  • read_only: Boolean indicating whether this index is read only.

Return value

string HTML for a search index.

1 theme call to theme_search_api_index()
search_api_admin_index_view in ./search_api.admin.inc
Page callback for displaying an index's status.

File

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

Code

function theme_search_api_index(array $variables) {
  $machine_name = $variables['machine_name'];
  $description = $variables['description'];
  $enabled = $variables['enabled'];
  $item_type = $variables['item_type'];
  $datasource_config = $variables['datasource_config'];
  $server = $variables['server'];
  $options = $variables['options'];
  $status = $variables['status'];
  $indexed_items = $variables['indexed_items'];
  $on_server = $variables['on_server'];
  $total_items = $variables['total_items'];

  // First, output the index description if there is one set.
  $output = '';
  if ($description) {
    $output .= '<p class="description">' . nl2br(check_plain($description)) . '</p>';
  }

  // Then, display a table summarizing the index's status.
  $rows = array();

  // Create a row template with references so we don't have to deal with the
  // complicated structure for each individual row.
  $row = array(
    'data' => array(
      array(
        'header' => TRUE,
      ),
      '',
    ),
    'class' => array(
      '',
    ),
  );
  $label =& $row['data'][0]['data'];
  $info =& $row['data'][1];
  $class =& $row['class'][0];
  $class = 'warning';
  if ($enabled) {
    $info = t('enabled (!disable_link)', array(
      '!disable_link' => l(t('disable'), 'admin/config/search/search_api/index/' . $machine_name . '/disable'),
    ));
    $class = 'ok';
  }
  elseif ($server) {
    $info = t('disabled (!enable_link)', array(
      '!enable_link' => l(t('enable'), 'admin/config/search/search_api/index/' . $machine_name . '/enable', array(
        'query' => array(
          'token' => drupal_get_token($machine_name),
        ),
      )),
    ));
  }
  else {
    $info = t('disabled');
  }
  $label = t('Status');
  $rows[] = _search_api_deep_copy($row);
  $class = '';
  $label = t('Item type');
  $type = search_api_get_item_type_info($item_type);
  $item_type = !empty($type['name']) ? $type['name'] : $item_type;
  $info = check_plain($item_type);
  $rows[] = _search_api_deep_copy($row);
  if ($datasource_config) {
    $label = t('Item type configuration');
    $info = check_plain($datasource_config);
    $rows[] = _search_api_deep_copy($row);
  }
  if ($server) {
    $label = t('Server');
    $info = l($server->name, 'admin/config/search/search_api/server/' . $server->machine_name);
    $rows[] = _search_api_deep_copy($row);
  }
  if ($enabled) {
    $options += array(
      'cron_limit' => SEARCH_API_DEFAULT_CRON_LIMIT,
    );
    if ($options['cron_limit']) {
      $class = 'ok';
      $info = format_plural($options['cron_limit'], 'During cron runs, 1 item will be indexed per batch.', 'During cron runs, @count items will be indexed per batch.');
    }
    else {
      $class = 'warning';
      $info = t('No items will be indexed during cron runs.');
    }
    $label = t('Cron batch size');
    $rows[] = _search_api_deep_copy($row);
    $theme = array(
      'percent' => $total_items ? (int) (100 * $indexed_items / $total_items) : 100,
      'message' => t('@indexed/@total indexed', array(
        '@indexed' => $indexed_items,
        '@total' => $total_items,
      )),
    );
    $output .= '<h3>' . t('Index status') . '</h3>';
    $output .= '<div class="search-api-index-status">' . theme('progress_bar', $theme) . '</div>';
    if (!isset($on_server)) {
      $info = t('An error occurred while trying to determine the server index status. Please check the logs for details.');
      $class = 'error';
    }
    else {
      $vars['@url'] = url('https://drupal.org/node/2009804#server-index-status');
      $info = format_plural($on_server, 'There is 1 item indexed on the server for this index. (<a href="@url">More information</a>)', 'There are @count items indexed on the server for this index. (<a href="@url">More information</a>)', $vars);
      $class = '';
    }
    $label = t('Server index status');
    $rows[] = _search_api_deep_copy($row);
  }
  if ($status != ENTITY_CUSTOM) {
    $label = t('Configuration status');
    $info = theme('entity_status', array(
      'status' => $status,
    ));
    $class = $status == ENTITY_OVERRIDDEN ? 'warning' : 'ok';
    $rows[] = _search_api_deep_copy($row);
  }
  $theme['rows'] = $rows;
  $theme['attributes']['class'][] = 'search-api-summary';
  $theme['attributes']['class'][] = 'search-api-index-summary';
  $theme['attributes']['class'][] = 'system-status-report';
  $output .= theme('table', $theme);
  return $output;
}