function search_api_admin_index_fields_submit in Search API 7
Form submission handler for search_api_admin_index_fields().
File
- ./
search_api.admin.inc, line 2173 - Administration page callbacks for the Search API module.
Code
function search_api_admin_index_fields_submit(array $form, array &$form_state) {
$index = $form_state['index'];
$options = isset($index->options) ? $index->options : array();
$index_path = 'admin/config/search/search_api/index/' . $index->machine_name;
if ($form_state['values']['op'] == t('Save changes')) {
$fields = $form_state['values']['fields'];
$default_types = search_api_default_field_types();
$custom_types = search_api_get_data_type_info();
foreach ($fields as $name => $field) {
if (empty($field['indexed'])) {
unset($fields[$name]);
}
else {
// Don't store the description. "indexed" is implied.
unset($fields[$name]['description'], $fields[$name]['indexed']);
// For non-default types, set type to the fallback and only real_type to
// the custom type.
$inner_type = search_api_extract_inner_type($field['type']);
if (!isset($default_types[$inner_type])) {
$fields[$name]['real_type'] = $field['type'];
$fields[$name]['type'] = search_api_nest_type($custom_types[$inner_type]['fallback'], $field['type']);
}
// Boost defaults to 1.0.
if ($field['boost'] == '1.0') {
unset($fields[$name]['boost']);
}
}
}
$options['fields'] = $fields;
unset($options['additional fields']);
$ret = $index
->update(array(
'options' => $options,
));
if ($ret) {
$vars = array(
'@url' => $index_path,
);
drupal_set_message(t('The indexed fields were successfully changed. The index was cleared and will have to be <a href="@url">re-indexed</a> with the new settings.', $vars));
}
else {
drupal_set_message(t('No values were changed.'));
}
if (isset($index->options['data_alter_callbacks']) || isset($index->options['processors'])) {
$form_state['redirect'] = $index_path . '/fields';
}
else {
drupal_set_message(t('Please set up the indexing workflow.'));
$form_state['redirect'] = $index_path . '/workflow';
}
return;
}
// Adding a related entity's fields.
$prefix = $form_state['values']['additional']['field'];
$options['additional fields'][$prefix] = $prefix;
$ret = $index
->update(array(
'options' => $options,
));
if ($ret) {
drupal_set_message(t('The available fields were successfully changed.'));
}
else {
drupal_set_message(t('No values were changed.'));
}
$form_state['redirect'] = $index_path . '/fields';
}