--- includes/callback_add_fulltext.old.inc 2011-02-25 15:06:44.000000000 +0100 +++ includes/callback_add_fulltext.inc 2011-02-25 13:44:40.000000000 +0100 @@ -49,10 +49,62 @@ class SearchApiAlterAddFulltext extends '#default_value' => $field['fields'], '#attributes' => array('class' => array('search-api-alter-add-fulltext-fields')), ); + if (empty($this->options)) { + $form['fields'][$name]['note'] = array( + '#markup' => '

' . t('Note: This is an automatically generated field, pre-configured to aggregate all fields with text content. You can change this configuration to your needs.') . '

', + '#weight' => -5, + ); + $form['fields'][$name]['name']['#default_value'] = t('Aggregated fulltext field'); + $form['fields'][$name]['fields']['#default_value'] = $this->getTextFields($this->index->entityWrapper(), $fields); + } } return $form; } + /** + * Helper function that returns all fields that have the original type "text". + * Copied from search_api_extract_fields(). + */ + protected function getTextFields(EntityMetadataWrapper $wrapper, array $fields, $pre = '') { + $ret = array(); + $wrapper_info = $wrapper->info(); + while (search_api_is_list_type($wrapper_info['type'])) { + $wrapper = $wrapper[0]; + $wrapper_info = $wrapper->info(); + } + $nested = array(); + foreach ($fields as $field => $info) { + $pos = strpos($field, ':'); + if ($pos === FALSE) { + try { + $property_info = $wrapper->$field->info(); + if (search_api_is_text_type($property_info['type'])) { + $ret[] = $pre . $field; + } + } + catch (EntityMetadataWrapperException $e) {} + } + else { + list($prefix, $key) = explode(':', $field, 2); + $nested[$prefix][$key] = $info; + } + } + + foreach ($nested as $prefix => $nested_fields) { + if (isset($wrapper->$prefix)) { + $ret = array_merge($ret, $this->getTextFields($wrapper->$prefix, $nested_fields, $pre . $prefix . ':')); + } + else { + foreach ($nested_fields as $field => $info) { + if (search_api_is_text_type($info['type'])) { + $ret[] = $pre . $field; + } + } + } + } + return $ret; + } + public function configurationFormValidate(array $form, array &$values, array &$form_state) { foreach ($values['fields'] as $name => $field) { if ($field['name'] && !$field['fields']) {