function search_api_admin_add_index in Search API 7
Form constructor for adding an index.
See also
search_api_admin_add_index_ajax_callback()
search_api_admin_add_index_validate()
search_api_admin_add_index_submit()
1 string reference to 'search_api_admin_add_index'
- search_api_menu in ./
search_api.module - Implements hook_menu().
File
- ./
search_api.admin.inc, line 709 - Administration page callbacks for the Search API module.
Code
function search_api_admin_add_index(array $form, array &$form_state) {
drupal_set_title(t('Add index'));
$old_type = empty($form_state['values']['item_type']) ? '' : $form_state['values']['item_type'];
$form['#attached']['css'][] = drupal_get_path('module', 'search_api') . '/search_api.admin.css';
$form['#tree'] = TRUE;
if (empty($form_state['step_one'])) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Index name'),
'#maxlength' => 50,
'#required' => TRUE,
);
$form['machine_name'] = array(
'#type' => 'machine_name',
'#maxlength' => 50,
'#machine_name' => array(
'exists' => 'search_api_index_load',
),
);
$form['item_type'] = array(
'#type' => 'select',
'#title' => t('Item type'),
'#description' => t('Select the type of items that will be indexed in this index. ' . 'This setting cannot be changed afterwards.'),
'#options' => array(),
'#required' => TRUE,
'#ajax' => array(
'callback' => 'search_api_admin_add_index_ajax_callback',
'wrapper' => 'search-api-datasource-options',
),
);
$form['datasource'] = array();
foreach (search_api_get_item_type_info() as $type => $info) {
$form['item_type']['#options'][$type] = $info['name'];
}
$form['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled'),
'#description' => t('This will only take effect if you also select a server for the index.'),
'#default_value' => TRUE,
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Index description'),
);
$form['server'] = array(
'#type' => 'select',
'#title' => t('Server'),
'#description' => t('Select the server this index should reside on.'),
'#default_value' => '',
'#options' => array(
'' => t('< No server >'),
),
);
$servers = search_api_server_load_multiple(FALSE, array(
'enabled' => 1,
));
// List enabled servers first.
foreach ($servers as $server) {
if ($server->enabled) {
$form['server']['#options'][$server->machine_name] = $server->name;
}
}
foreach ($servers as $server) {
if (!$server->enabled) {
$form['server']['#options'][$server->machine_name] = t('@server_name (disabled)', array(
'@server_name' => $server->name,
));
}
}
$form['read_only'] = array(
'#type' => 'checkbox',
'#title' => t('Read only'),
'#description' => t('Do not write to this index or track the status of items in this index.'),
'#default_value' => FALSE,
);
$form['options']['index_directly'] = array(
'#type' => 'checkbox',
'#title' => t('Index items immediately'),
'#description' => t('Immediately index new or updated items instead of waiting for the next cron run. ' . 'This might have serious performance drawbacks and is generally not advised for larger sites.'),
'#default_value' => FALSE,
);
$form['options']['cron_limit'] = array(
'#type' => 'textfield',
'#title' => t('Cron batch size'),
'#description' => t('Set how many items will be indexed at once when indexing items during a cron run. ' . '"0" means that no items will be indexed by cron for this index, "-1" means that cron should index all items at once.'),
'#default_value' => SEARCH_API_DEFAULT_CRON_LIMIT,
'#size' => 4,
'#attributes' => array(
'class' => array(
'search-api-cron-limit',
),
),
'#element_validate' => array(
'element_validate_integer',
),
);
}
elseif (!$old_type) {
$old_type = $form_state['step_one']['item_type'];
}
if ($old_type) {
$datasource = search_api_get_datasource_controller($old_type);
$datasource_form = array();
$datasource_form = $datasource
->configurationForm($datasource_form, $form_state);
if ($datasource_form) {
$form['datasource'] = $datasource_form;
$form['datasource']['#parents'] = array(
'options',
'datasource',
);
}
}
$form['datasource']['#prefix'] = '<div id="search-api-datasource-options">';
$form['datasource']['#suffix'] = '</div>';
$form['old_type'] = array(
'#type' => 'value',
'#value' => $old_type,
);
$form['datasource_config'] = array(
'#type' => 'value',
'#value' => !empty($datasource_form),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Create index'),
);
return $form;
}