function search_api_admin_index_workflow_submit in Search API 7
Form submission handler for search_api_admin_index_workflow().
See also
search_api_admin_index_workflow_validate()
File
- ./
search_api.admin.inc, line 1721 - Administration page callbacks for the Search API module.
Code
function search_api_admin_index_workflow_submit(array $form, array &$form_state) {
$values = $form_state['values'];
unset($values['callbacks']['settings']);
unset($values['processors']['settings']);
$index = $form_state['index'];
$index_path = 'admin/config/search/search_api/index/' . $index->machine_name;
$options = empty($index->options) ? array() : $index->options;
// Store callback and processor settings.
foreach ($form_state['callbacks'] as $name => $callback) {
$callback_form = isset($form['callbacks']['settings'][$name]) ? $form['callbacks']['settings'][$name] : array();
$values['callbacks'][$name] += array(
'settings' => array(),
);
$values['callbacks'][$name]['settings'] = $callback
->configurationFormSubmit($callback_form, $values['callbacks'][$name]['settings'], $form_state);
}
foreach ($form_state['processors'] as $name => $processor) {
$processor_form = isset($form['processors']['settings'][$name]) ? $form['processors']['settings'][$name] : array();
$values['processors'][$name] += array(
'settings' => array(),
);
$values['processors'][$name]['settings'] = $processor
->configurationFormSubmit($processor_form, $values['processors'][$name]['settings'], $form_state);
}
$types = search_api_field_types();
foreach ($form_state['callbacks'] as $name => $callback) {
// Check whether callback status has changed.
if ($values['callbacks'][$name]['status'] == empty($options['data_alter_callbacks'][$name]['status'])) {
$callbacks_changed = TRUE;
if ($values['callbacks'][$name]['status']) {
// Callback was just enabled, add its fields.
$properties = $callback
->propertyInfo();
if ($properties) {
foreach ($properties as $key => $field) {
$type = $field['type'];
$inner = search_api_extract_inner_type($type);
if ($inner != 'token' && empty($types[$inner])) {
// Someone apparently added a structure or entity as a property in
// a data alteration.
continue;
}
if ($inner == 'token' || search_api_is_text_type($inner) && !empty($field['options list'])) {
$old = $type;
$type = 'string';
while (search_api_is_list_type($old)) {
$old = substr($old, 5, -1);
$type = "list<{$type}>";
}
}
$index->options['fields'][$key] = array(
'type' => $type,
);
}
}
}
}
}
if (!isset($options['data_alter_callbacks']) || !isset($options['processors']) || $options['data_alter_callbacks'] != $values['callbacks'] || $options['processors'] != $values['processors']) {
$index->options['data_alter_callbacks'] = $values['callbacks'];
$index->options['processors'] = $values['processors'];
// Save the already sorted arrays to avoid having to sort them at each use.
uasort($index->options['data_alter_callbacks'], 'search_api_admin_element_compare');
uasort($index->options['processors'], 'search_api_admin_element_compare');
// Re-calculate the fields, since they might have changed in hard-to-predict
// ways.
search_api_index_recalculate_fields(array(
$index,
));
$index
->save();
$index
->reindex();
$vars = array(
'@url' => url($index_path),
);
drupal_set_message(t('The indexing workflow was successfully edited. All content was scheduled for <a href="@url">re-indexing</a> so the new settings can take effect.', $vars));
}
else {
drupal_set_message(t('No values were changed.'));
}
$form_state['redirect'] = $index_path . '/workflow';
}