You are here

public function SearchApiSolrBackend::buildConfigurationForm in Search API Solr 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::buildConfigurationForm()
  2. 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::buildConfigurationForm()
  3. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::buildConfigurationForm()

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PluginFormInterface::buildConfigurationForm

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 187

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  if (!$this->server
    ->isNew()) {

    // Editing this server.
    $form['server_description'] = array(
      '#type' => 'item',
      '#title' => $this
        ->t('Solr server URI'),
      '#description' => $this
        ->getSolrConnector()
        ->getServerLink(),
    );
  }
  $solr_connector_options = $this
    ->getSolrConnectorOptions();
  $form['connector'] = array(
    '#type' => 'radios',
    '#title' => $this
      ->t('Solr Connector'),
    '#description' => $this
      ->t('Choose a connector to use for this Solr server.'),
    '#options' => $solr_connector_options,
    '#default_value' => $this->configuration['connector'],
    '#required' => TRUE,
    '#ajax' => array(
      'callback' => [
        get_class($this),
        'buildAjaxSolrConnectorConfigForm',
      ],
      'wrapper' => 'search-api-solr-connector-config-form',
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );
  $this
    ->buildConnectorConfigForm($form, $form_state);
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Advanced'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['advanced']['retrieve_data'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Retrieve result data from Solr'),
    '#description' => $this
      ->t('When checked, result data will be retrieved directly from the Solr server. This might make item loads unnecessary. Only indexed fields can be retrieved. Note also that the returned field data might not always be correct, due to preprocessing and caching issues.'),
    '#default_value' => $this->configuration['retrieve_data'],
  );
  $form['advanced']['highlight_data'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Highlight retrieved data'),
    '#description' => $this
      ->t('When retrieving result data from the Solr server, try to highlight the search terms in the returned fulltext fields.'),
    '#default_value' => $this->configuration['highlight_data'],
  );
  $form['advanced']['excerpt'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Return an excerpt for all results'),
    '#description' => $this
      ->t("If search keywords are given, use Solr's capabilities to create a highlighted search excerpt for each result. Whether the excerpts will actually be displayed depends on the settings of the search, though."),
    '#default_value' => $this->configuration['excerpt'],
  );
  $form['advanced']['skip_schema_check'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Skip schema verification'),
    '#description' => $this
      ->t('Skip the automatic check for schema-compatibillity. Use this override if you are seeing an error-message about an incompatible schema.xml configuration file, and you are sure the configuration is compatible.'),
    '#default_value' => $this->configuration['skip_schema_check'],
  );

  // Highlighting retrieved data only makes sense when we retrieve data.
  // (Actually, internally it doesn't really matter. However, from a user's
  // perspective, having to check both probably makes sense.)
  $form['advanced']['highlight_data']['#states']['invisible'][':input[name="backend_config[advanced][retrieve_data]"]']['checked'] = FALSE;
  if ($this->moduleHandler
    ->moduleExists('search_api_autocomplete')) {
    $form['autocomplete'] = array(
      '#type' => 'details',
      '#title' => $this
        ->t('Autocomplete settings'),
      '#description' => $this
        ->t('These settings allow you to configure how suggestions are computed when autocompletion is used. If you are seeing many inappropriate suggestions you might want to deactivate the corresponding suggestion type. You can also deactivate one method to speed up the generation of suggestions.'),
    );
    $form['autocomplete']['suggest_suffix'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Suggest word endings'),
      '#description' => $this
        ->t('Suggest endings for the currently entered word.'),
      '#default_value' => $this->configuration['suggest_suffix'],
    );
    $form['autocomplete']['suggest_corrections'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Suggest corrected words'),
      '#description' => $this
        ->t('Suggest corrections for the currently entered words.'),
      '#default_value' => $this->configuration['suggest_corrections'],
    );
    $form['autocomplete']['suggest_words'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Suggest additional words'),
      '#description' => $this
        ->t('Suggest additional words the user might want to search for.'),
      '#default_value' => $this->configuration['suggest_words'],
      // @todo
      '#disabled' => TRUE,
    );
  }
  $form['multisite'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Multi-site compatibility'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => $this
      ->t("By default a single Solr backend based Search API server is able to index the data of multiple Drupal sites. But this is an expert-only and dangerous feature that mainly exists for backward compatibility. If you really index multiple sites in one index and don't activate 'Retrieve results for this site only' below you have to ensure that you enable 'Retrieve result data from Solr'! Otherwise it could lead to any kind of errors!"),
  );
  $description = $this
    ->t("Automatically filter all searches to only retrieve results from this Drupal site. The default and intended behavior is to display results from all sites. WARNING: Enabling this filter might break features like autocomplete, spell checking or suggesters!");
  $form['multisite']['site_hash'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Retrieve results for this site only'),
    '#description' => $description,
    '#default_value' => $this->configuration['site_hash'],
  );
  return $form;
}