You are here

public function SolrConnectorPluginBase::buildConfigurationForm in Search API Solr 4.x

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

2 calls to SolrConnectorPluginBase::buildConfigurationForm()
Solr36Connector::buildConfigurationForm in modules/search_api_solr_legacy/src/Plugin/SolrConnector/Solr36Connector.php
Form constructor.
StandardSolrCloudConnector::buildConfigurationForm in src/Plugin/SolrConnector/StandardSolrCloudConnector.php
Form constructor.
2 methods override SolrConnectorPluginBase::buildConfigurationForm()
Solr36Connector::buildConfigurationForm in modules/search_api_solr_legacy/src/Plugin/SolrConnector/Solr36Connector.php
Form constructor.
StandardSolrCloudConnector::buildConfigurationForm in src/Plugin/SolrConnector/StandardSolrCloudConnector.php
Form constructor.

File

src/SolrConnector/SolrConnectorPluginBase.php, line 132

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'] = [
    '#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' => [
      'http' => 'http',
      'https' => 'https',
    ],
  ];
  $form['host'] = [
    '#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'] = [
    '#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'] = [
    '#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'] = [
    '#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'] : '',
    '#required' => TRUE,
  ];
  $form['timeout'] = [
    '#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[self::INDEX_TIMEOUT] = [
    '#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[self::INDEX_TIMEOUT]) ? $this->configuration[self::INDEX_TIMEOUT] : 5,
    '#required' => TRUE,
  ];
  $form[self::OPTIMIZE_TIMEOUT] = [
    '#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[self::OPTIMIZE_TIMEOUT]) ? $this->configuration[self::OPTIMIZE_TIMEOUT] : 10,
    '#required' => TRUE,
  ];
  $form[self::FINALIZE_TIMEOUT] = [
    '#type' => 'number',
    '#min' => 1,
    '#max' => 180,
    '#title' => $this
      ->t('Finalize timeout'),
    '#description' => $this
      ->t('The timeout in seconds for index finalization queries on a Solr server.'),
    '#default_value' => isset($this->configuration[self::FINALIZE_TIMEOUT]) ? $this->configuration[self::FINALIZE_TIMEOUT] : 30,
    '#required' => TRUE,
  ];
  $form['commit_within'] = [
    '#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'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Connector Workarounds'),
  ];
  $form['workarounds']['solr_version'] = [
    '#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' => [
      '' => $this
        ->t('Determine automatically'),
      '6' => '6.x',
      '7' => '7.x',
      '8' => '8.x',
    ],
    '#default_value' => $this->configuration['solr_version'] ?? '',
  ];
  $form['workarounds']['http_method'] = [
    '#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' => $this->configuration['http_method'] ?? 'AUTO',
    '#options' => [
      'AUTO' => $this
        ->t('AUTO'),
      'POST' => 'POST',
      'GET' => 'GET',
    ],
  ];
  $form['workarounds']['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'] ?? FALSE,
  ];
  $form['advanced'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced server configuration'),
  ];
  $form['advanced']['jmx'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable JMX'),
    '#description' => $this
      ->t('Enable JMX based monitoring.'),
    '#default_value' => $this->configuration['jmx'] ?? FALSE,
  ];
  $form['advanced']['jts'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable JTS'),
    '#description' => $this
      ->t('Enable JTS (java topographic suite). Be sure to follow instructions in last solr reference guide about how to use spatial search.'),
    '#default_value' => $this->configuration['jts'] ?? FALSE,
  ];
  $form['advanced']['solr_install_dir'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('solr.install.dir'),
    '#description' => $this
      ->t('The path where Solr is installed on the server, relative to the configuration or absolute. Some examples are "../../.." for Solr downloaded from apache.org, "/usr/local/opt/solr" for installations via homebrew on macOS or "/opt/solr" for some linux distributions and for the official Solr docker container. If you use different systems for development, testing and production you can use drupal config overwrites to adjust the value per environment or adjust the generated solrcore.properties per environment or use java virtual machine options (-D) to set the property. Modern Solr installations should set that virtual machine option correctly in their start script by themselves. In this case this field should be left empty!'),
    '#default_value' => isset($this->configuration['solr_install_dir']) ? $this->configuration['solr_install_dir'] : '',
  ];
  return $form;
}