You are here

public function SolrConnectorPluginBase::buildConfigurationForm in Search API Solr 8

Same name and namespace in other branches
  1. 8.3 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::buildConfigurationForm()
  2. 8.2 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::buildConfigurationForm()
  3. 4.x src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::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

1 call to SolrConnectorPluginBase::buildConfigurationForm()
BasicAuthSolrConnector::buildConfigurationForm in src/Plugin/SolrConnector/BasicAuthSolrConnector.php
Form constructor.
1 method overrides SolrConnectorPluginBase::buildConfigurationForm()
BasicAuthSolrConnector::buildConfigurationForm in src/Plugin/SolrConnector/BasicAuthSolrConnector.php
Form constructor.

File

src/SolrConnector/SolrConnectorPluginBase.php, line 111

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form['scheme'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('HTTP protocol'),
    '#description' => $this
      ->t('The HTTP protocol to use for sending queries.'),
    '#default_value' => isset($this->configuration['scheme']) ? $this->configuration['scheme'] : 'http',
    '#options' => array(
      'http' => 'http',
      'https' => 'https',
    ),
  );
  $form['host'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Solr host'),
    '#description' => $this
      ->t('The host name or IP of your Solr server, e.g. <code>localhost</code> or <code>www.example.com</code>.'),
    '#default_value' => isset($this->configuration['host']) ? $this->configuration['host'] : '',
    '#required' => TRUE,
  );
  $form['port'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Solr port'),
    '#description' => $this
      ->t('The Jetty example server is at port 8983, while Tomcat uses 8080 by default.'),
    '#default_value' => isset($this->configuration['port']) ? $this->configuration['port'] : '',
    '#required' => TRUE,
  );
  $form['path'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Solr path'),
    '#description' => $this
      ->t('The path that identifies the Solr instance to use on the server.'),
    '#default_value' => isset($this->configuration['path']) ? $this->configuration['path'] : '',
  );
  $form['core'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Solr core'),
    '#description' => $this
      ->t('The name that identifies the Solr core to use on the server.'),
    '#default_value' => isset($this->configuration['core']) ? $this->configuration['core'] : '',
  );
  $form['timeout'] = array(
    '#type' => 'number',
    '#min' => 1,
    '#max' => 180,
    '#title' => $this
      ->t('Query timeout'),
    '#description' => $this
      ->t('The timeout in seconds for search queries sent to the Solr server.'),
    '#default_value' => isset($this->configuration['timeout']) ? $this->configuration['timeout'] : 5,
    '#required' => TRUE,
  );
  $form['index_timeout'] = array(
    '#type' => 'number',
    '#min' => 1,
    '#max' => 180,
    '#title' => $this
      ->t('Index timeout'),
    '#description' => $this
      ->t('The timeout in seconds for indexing requests to the Solr server.'),
    '#default_value' => isset($this->configuration['index_timeout']) ? $this->configuration['index_timeout'] : 5,
    '#required' => TRUE,
  );
  $form['optimize_timeout'] = array(
    '#type' => 'number',
    '#min' => 1,
    '#max' => 180,
    '#title' => $this
      ->t('Optimize timeout'),
    '#description' => $this
      ->t('The timeout in seconds for background index optimization queries on a Solr server.'),
    '#default_value' => isset($this->configuration['optimize_timeout']) ? $this->configuration['optimize_timeout'] : 10,
    '#required' => TRUE,
  );
  $form['commit_within'] = array(
    '#type' => 'number',
    '#min' => 0,
    '#title' => $this
      ->t('Commit within'),
    '#description' => $this
      ->t('The limit in milliseconds within a (soft) commit on Solr is forced after any updating the index in any way. Setting the value to "0" turns off this dynamic enforcement and lets Solr behave like configured solrconf.xml.'),
    '#default_value' => isset($this->configuration['commit_within']) ? $this->configuration['commit_within'] : 1000,
    '#required' => TRUE,
  );
  $form['workarounds'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Connector Workarounds'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['workarounds']['solr_version'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Solr version override'),
    '#description' => $this
      ->t('Specify the Solr version manually in case it cannot be retrived automatically. The version can be found in the Solr admin interface under "Solr Specification Version" or "solr-spec"'),
    '#options' => array(
      '' => $this
        ->t('Determine automatically'),
      '4' => '4.x',
      '5' => '5.x',
      '6' => '6.x',
    ),
    '#default_value' => isset($this->configuration['solr_version']) ? $this->configuration['solr_version'] : '',
  );
  $form['workarounds']['http_method'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('HTTP method'),
    '#description' => $this
      ->t('The HTTP method to use for sending queries. GET will often fail with larger queries, while POST should not be cached. AUTO will use GET when possible, and POST for queries that are too large.'),
    '#default_value' => isset($this->configuration['http_method']) ? $this->configuration['http_method'] : 'AUTO',
    '#options' => array(
      'AUTO' => $this
        ->t('AUTO'),
      'POST' => 'POST',
      'GET' => 'GET',
    ),
  );
  return $form;
}