You are here

public function SearchApiAutocompleteLiveResultsSuggester::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/SearchApiAutocompleteLiveResultsSuggester.php, line 29
Contains SearchApiAutocompleteLiveResultsSuggester.

Class

SearchApiAutocompleteLiveResultsSuggester
Provides a suggester plugin that retrieves Live Results.

Code

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

  // Add a list of fields to include for autocomplete searches.
  $index = $this
    ->getSearch()
    ->index();
  $fields = $index
    ->getFields();
  $fulltext_fields = $index
    ->getFulltextFields();
  $options = array();
  foreach ($fulltext_fields as $field) {
    $options[$field] = check_plain($fields[$field]['name']);
  }
  $form['display'] = array(
    '#type' => 'radios',
    '#title' => t('Display method'),
    '#description' => t('The way the results should be displayed.'),
    '#options' => array(
      'view_mode' => t("Use view mode: 'Live result search' to display results"),
      'title' => t("Only show title (linked to node)"),
    ),
    '#default_value' => $this->configuration['display'],
    '#access' => $index
      ->getEntityType(),
  );
  $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;
}