You are here

public function SearchApiSolrBackend::buildConfigurationForm in Search API Solr 8.2

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 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

2 calls to SearchApiSolrBackend::buildConfigurationForm()
AbstractSearchApiSolrMultilingualBackend::buildConfigurationForm in src/Plugin/search_api/backend/AbstractSearchApiSolrMultilingualBackend.php
Form constructor.
SearchApiSolrAnySchemaBackend::buildConfigurationForm in src/Plugin/search_api/backend/SearchApiSolrAnySchemaBackend.php
Form constructor.
2 methods override SearchApiSolrBackend::buildConfigurationForm()
AbstractSearchApiSolrMultilingualBackend::buildConfigurationForm in src/Plugin/search_api/backend/AbstractSearchApiSolrMultilingualBackend.php
Form constructor.
SearchApiSolrAnySchemaBackend::buildConfigurationForm in src/Plugin/search_api/backend/SearchApiSolrAnySchemaBackend.php
Form constructor.

File

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

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'] = [
      '#type' => 'item',
      '#title' => $this
        ->t('Solr server URI'),
      '#description' => $this
        ->getSolrConnector()
        ->getServerLink(),
    ];
  }
  $solr_connector_options = $this
    ->getSolrConnectorOptions();
  $form['connector'] = [
    '#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' => [
      'callback' => [
        get_class($this),
        'buildAjaxSolrConnectorConfigForm',
      ],
      'wrapper' => 'search-api-solr-connector-config-form',
      'method' => 'replace',
      'effect' => 'fade',
    ],
  ];
  $this
    ->buildConnectorConfigForm($form, $form_state);
  $form['advanced'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced'),
  ];
  $form['advanced']['retrieve_data'] = [
    '#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'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Retrieve highlighted snippets'),
    '#description' => $this
      ->t('Return a highlighted version of the indexed fulltext fields. These will be used by the "Highlighting Processor" directly instead of applying its own PHP algorithm.'),
    '#default_value' => $this->configuration['highlight_data'],
  ];
  $form['advanced']['skip_schema_check'] = [
    '#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'],
  ];
  $form['advanced']['server_prefix'] = [
    '#type' => 'textfield',
    '#title' => t('All index prefix'),
    '#description' => t("By default, the index ID in the Solr server is the same as the index's machine name in Drupal. This setting will let you specify an additional prefix. Only use alphanumeric characters and underscores. Since changing the prefix makes the currently indexed data inaccessible, you should not change this variable when no data is indexed."),
    '#default_value' => $this->configuration['server_prefix'],
  ];
  $domains = SolrFieldType::getAvailableDomains();
  $form['advanced']['domain'] = [
    '#type' => 'select',
    '#options' => array_combine($domains, $domains),
    '#title' => $this
      ->t('Targeted content domain'),
    '#description' => $this
      ->t('For example "UltraBot3000" would be indexed as "Ultra" "Bot" "3000" in a generic domain, "CYP2D6" has to stay like it is in a scientific domain.'),
    '#default_value' => isset($this->configuration['domain']) ? $this->configuration['domain'] : 'generic',
  ];
  $form['multisite'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Multi-site compatibility'),
    '#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'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Retrieve results for this site only'),
    '#description' => $description,
    '#default_value' => $this->configuration['site_hash'],
  ];
  return $form;
}