function search_api_admin_index_edit in Search API 7
Form constructor for editing an index's settings.
Parameters
SearchApiIndex $index: The index to edit.
See also
search_api_admin_index_edit_validate()
search_api_admin_index_edit_submit()
1 string reference to 'search_api_admin_index_edit'
- search_api_menu in ./
search_api.module - Implements hook_menu().
File
- ./
search_api.admin.inc, line 1306 - Administration page callbacks for the Search API module.
Code
function search_api_admin_index_edit(array $form, array &$form_state, SearchApiIndex $index) {
$form_state['index'] = $index;
$form['#attached']['css'][] = drupal_get_path('module', 'search_api') . '/search_api.admin.css';
$form['#tree'] = TRUE;
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Index name'),
'#maxlength' => 50,
'#default_value' => $index->name,
'#required' => TRUE,
);
try {
$enabled_fixed = !$index
->server();
} catch (Exception $e) {
watchdog_exception('search_api', $e);
// The exception only occurs if the index is disabled, and for an unknown
// server we of course want do prevent the index from being enabled.
$enabled_fixed = TRUE;
}
$form['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled'),
'#default_value' => $index->enabled,
// Can't enable an index that's not lying on any server.
'#disabled' => $enabled_fixed,
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Index description'),
'#default_value' => $index->description,
);
$form['server'] = array(
'#type' => 'select',
'#title' => t('Server'),
'#description' => t('Select the server this index should reside on.'),
'#default_value' => $index->server,
'#options' => array(
'' => t('< No server >'),
),
);
$servers = search_api_server_load_multiple(FALSE, array(
'enabled' => 1,
));
// List enabled servers first.
foreach ($servers as $server) {
$form['server']['#options'][$server->machine_name] = $server->name;
}
$datasource_form = !empty($form['options']['datasource']) ? $form['options']['datasource'] : array();
$datasource_form = $index
->datasource()
->configurationForm($datasource_form, $form_state);
if ($datasource_form) {
$form['options']['datasource'] = $datasource_form;
$form['options']['datasource']['#type'] = 'fieldset';
$form['options']['datasource']['#title'] = t('Datasource options');
}
$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' => $index->read_only,
);
$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' => !empty($index->options['index_directly']),
'#states' => array(
'invisible' => array(
':input[name="read_only"]' => array(
'checked' => TRUE,
),
),
),
);
$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' => isset($index->options['cron_limit']) ? $index->options['cron_limit'] : SEARCH_API_DEFAULT_CRON_LIMIT,
'#size' => 4,
'#attributes' => array(
'class' => array(
'search-api-cron-limit',
),
),
'#element_validate' => array(
'_element_validate_integer',
),
'#states' => array(
'invisible' => array(
':input[name="read_only"]' => array(
'checked' => TRUE,
),
),
),
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save settings'),
);
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#submit' => array(
'search_api_admin_form_delete_submit',
),
'#limit_validation_errors' => array(),
);
return $form;
}