function search_api_live_results_admin_overview in Search API live results 7
Form displaying an overview over all searches available for autocompletion.
Parameters
SearchApiIndex $index: The index for which autocompletion searches should be configured.
See also
search_api_live_results_admin_overview_submit()
search_api_live_results_admin_overview_submit_delete()
1 string reference to 'search_api_live_results_admin_overview'
- search_api_live_results_menu in ./
search_api_live_results.module - Implements hook_menu().
File
- includes/
search_api_live_results.admin.inc, line 18 - Contains page callbacks and related functions for the admin UI.
Code
function search_api_live_results_admin_overview(array $form, array &$form_state, SearchApiIndex $index) {
$form = array();
$form_state['index'] = $index;
$index_id = $index->machine_name;
$server = $index
->server();
if (!$server) {
if (search_api_live_results_search_load_multiple(FALSE, array(
'index_id' => $index_id,
))) {
$form['description'] = array(
'#type' => 'item',
'#title' => t('Delete live results settings'),
'#description' => t("If you won't use live results with this index anymore, you can delete all live results settings associated with it. " . "This will delete all live results settings on this index. Settings on other indexes won't be influenced."),
);
$form['button'] = array(
'#type' => 'submit',
'#value' => t('Delete live results settings'),
'#submit' => array(
'search_api_live_results_admin_overview_submit_delete',
),
);
}
return $form;
}
$form['#tree'] = TRUE;
$types = search_api_live_results_get_types();
$searches = search_api_live_results_search_load_multiple(FALSE, array(
'index_id' => $index_id,
));
$show_status = FALSE;
foreach ($types as $type => $info) {
if (empty($info['list searches'])) {
continue;
}
$t_searches = $info['list searches']($index);
if (empty($t_searches)) {
$t_searches = array();
}
foreach ($t_searches as $id => $search) {
if (isset($searches[$id])) {
$types[$type]['searches'][$id] = $searches[$id];
$show_status |= $searches[$id]
->hasStatus(ENTITY_IN_CODE);
unset($searches[$id]);
}
else {
$search += array(
'machine_name' => $id,
'index_id' => $index_id,
'type' => $type,
'enabled' => 0,
'options' => array(),
);
$search['options'] += array(
'result count' => TRUE,
);
$types[$type]['searches'][$id] = entity_create('search_api_live_results_search', $search);
}
}
}
foreach ($searches as $id => $search) {
$search->unavailable = TRUE;
$type = isset($types[$search->type]) ? $search->type : '';
$types[$type]['searches'][$id] = $search;
$show_status |= $search
->hasStatus(ENTITY_IN_CODE);
}
$base_path = 'admin/config/search/search_api/index/' . $index_id . '/live-results/';
foreach ($types as $type => $info) {
if (empty($info['searches'])) {
continue;
}
if (!$type) {
$info += array(
'name' => t('Unavailable search types'),
'description' => t('The modules providing these searches were disabled or uninstalled. ' . "If you won't use them anymore, you can delete their settings."),
);
}
$form[$type] = array(
'#type' => 'fieldset',
'#title' => $info['name'],
);
if (!empty($info['description'])) {
$form[$type]['#description'] = '<p>' . $info['description'] . '</p>';
}
$form[$type]['searches']['#theme'] = 'tableselect';
$form[$type]['searches']['#header'] = array();
if ($show_status) {
$form[$type]['searches']['#header']['status'] = t('Status');
}
$form[$type]['searches']['#header'] += array(
'name' => t('Name'),
'operations' => t('Operations'),
);
$form[$type]['searches']['#empty'] = '';
$form[$type]['searches']['#js_select'] = TRUE;
foreach ($info['searches'] as $id => $search) {
$form[$type]['searches'][$id] = array(
'#type' => 'checkbox',
'#default_value' => $search->enabled,
'#parents' => array(
'searches',
$id,
),
);
if (!empty($search->unavailabe)) {
$form[$type]['searches'][$id]['#default_value'] = FALSE;
$form[$type]['searches'][$id]['#disabled'] = TRUE;
}
$form_state['searches'][$id] = $search;
$options =& $form[$type]['searches']['#options'][$id];
if ($show_status) {
$options['status'] = isset($search->status) ? theme('entity_status', array(
'status' => $search->status,
)) : '';
}
$options['name'] = $search->name;
$items = array();
if (empty($search->unavailabe) && !empty($search->id)) {
$items[] = l(t('edit'), $base_path . $id . '/edit');
}
if (!empty($search->status) && $search
->hasStatus(ENTITY_CUSTOM)) {
$title = $search
->hasStatus(ENTITY_IN_CODE) ? t('revert') : t('delete');
$items[] = l($title, $base_path . $id . '/delete');
}
if ($items) {
$variables = array(
'items' => $items,
'attributes' => array(
'class' => array(
'inline',
),
),
);
$options['operations'] = theme('item_list', $variables);
}
else {
$options['operations'] = '';
}
unset($options);
}
}
if (empty($form)) {
$form['message']['#markup'] = '<p>' . t('There are currently no searches known for this index.') . '</p>';
}
else {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
}
return $form;
}