public function SearchApiAlterAddHierarchy::configurationFormSubmit in Search API 7
Implements SearchApiAlterCallbackInterface::configurationFormSubmit().
Overrides SearchApiAbstractAlterCallback::configurationFormSubmit
File
- includes/
callback_add_hierarchy.inc, line 56 - Contains SearchApiAlterAddHierarchy.
Class
- SearchApiAlterAddHierarchy
- Adds all ancestors for hierarchical fields.
Code
public function configurationFormSubmit(array $form, array &$values, array &$form_state) {
// Change the saved type of fields in the index, if necessary.
if (!empty($this->index->options['fields'])) {
$fields =& $this->index->options['fields'];
$previous = drupal_map_assoc($this->options['fields']);
foreach ($values['fields'] as $field) {
list($key) = explode(':', $field);
if (empty($previous[$field]) && isset($fields[$key]['type'])) {
$fields[$key]['type'] = 'list<' . search_api_extract_inner_type($fields[$key]['type']) . '>';
$change = TRUE;
}
}
$new = drupal_map_assoc($values['fields']);
foreach ($previous as $field) {
list($key) = explode(':', $field);
if (empty($new[$field]) && isset($fields[$key]['type'])) {
$w = $this->index
->entityWrapper(NULL, FALSE);
if (isset($w->{$key})) {
$type = $w->{$key}
->type();
$inner = search_api_extract_inner_type($fields[$key]['type']);
$fields[$key]['type'] = search_api_nest_type($inner, $type);
$change = TRUE;
}
}
}
if (isset($change)) {
$this->index
->save();
}
}
return parent::configurationFormSubmit($form, $values, $form_state);
}