public function SolrConnectorPluginBase::validateConfigurationForm in Search API Solr 8
Same name and namespace in other branches
- 8.3 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::validateConfigurationForm()
- 8.2 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::validateConfigurationForm()
- 4.x src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::validateConfigurationForm()
Form validation handler.
Parameters
array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the complete form.
Overrides PluginFormTrait::validateConfigurationForm
See also
\Drupal\Core\Plugin\PluginFormInterface::validateConfigurationForm()
File
- src/
SolrConnector/ SolrConnectorPluginBase.php, line 230
Class
- SolrConnectorPluginBase
- Defines a base class for Solr connector plugins.
Namespace
Drupal\search_api_solr\SolrConnectorCode
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
if (isset($values['port']) && (!is_numeric($values['port']) || $values['port'] < 0 || $values['port'] > 65535)) {
$form_state
->setError($form['port'], $this
->t('The port has to be an integer between 0 and 65535.'));
}
if (!empty($values['path']) && strpos($values['path'], '/') !== 0) {
$form_state
->setError($form['path'], $this
->t('If provided the path has to start with "/".'));
}
if (!empty($values['core']) && strpos($values['core'], '/') === 0) {
$form_state
->setError($form['core'], $this
->t('The core must not start with "/".'));
}
if (!$form_state
->hasAnyErrors()) {
// Try to orchestrate a server link from form values.
$values_copied = $values;
// Solr 3 doesn't have the core name in the path. But solarium 6 needs it.
// The period is a workaround that gives us URLs like "solr/./select".
if (!$values_copied['core']) {
$values_copied['core'] = '.';
}
$solr = $this
->createClient($values_copied);
$solr
->createEndpoint($values + [
'key' => 'core',
], TRUE);
try {
$this
->getServerLink();
} catch (\InvalidArgumentException $e) {
foreach ([
'scheme',
'host',
'port',
'path',
'core',
] as $part) {
$form_state
->setError($form[$part], $this
->t('The server link generated from the form values is illegal.'));
}
}
}
}