You are here

public function SearchApiAutocompleteServerSuggester::buildConfigurationForm in Search API Autocomplete 7

Constructs the plugin's configuration form.

Parameters

array $form: An associative array containing the structure of the form.

array $form_state: The current state of the form.

Return value

array An associative array containing the structure of the form. An empty array if the plugin has no configuration form.

Overrides SearchApiAutocompleteSuggesterPluginBase::buildConfigurationForm

File

src/SearchApiAutocompleteServerSuggester.php, line 40
Contains SearchApiAutocompleteServerSuggester.

Class

SearchApiAutocompleteServerSuggester
Provides a suggester plugin that retrieves suggestions from the server.

Code

public function buildConfigurationForm(array $form, array &$form_state) {

  // Add a list of fields to include for autocomplete searches.
  $search = $this
    ->getSearch();
  $fields = $search
    ->index()
    ->getFields();
  $fulltext_fields = $search
    ->index()
    ->getFulltextFields();
  $options = array();
  foreach ($fulltext_fields as $field) {
    $options[$field] = check_plain($fields[$field]['name']);
  }
  $form['fields'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Override used fields'),
    '#description' => t('Select the fields which should be searched for matches when looking for autocompletion suggestions. Leave blank to use the same fields as the underlying search.'),
    '#options' => $options,
    '#default_value' => drupal_map_assoc($this->configuration['fields']),
    '#attributes' => array(
      'class' => array(
        'search-api-checkboxes-list',
      ),
    ),
  );
  $form['#attached']['css'][] = drupal_get_path('module', 'search_api') . '/search_api.admin.css';
  return $form;
}