public function ServerForm::validateForm in Search API 8
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ ServerForm.php, line 265
Class
- ServerForm
- Provides a form for creating and editing search servers.
Namespace
Drupal\search_api\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
/** @var \Drupal\search_api\ServerInterface $server */
$server = $this
->getEntity();
// Check if the backend plugin changed.
$backend_id = $server
->getBackendId();
if ($backend_id != $form_state
->get('backend')) {
// This can only happen during initial server creation, since we don't
// allow switching the backend afterwards. The user has selected a
// different backend, so any values entered for the other backend should
// be discarded.
$input =& $form_state
->getUserInput();
$input['backend_config'] = [];
$new_backend = $this->backendPluginManager
->createInstance($form_state
->getValue('backend'));
if ($new_backend instanceof PluginFormInterface) {
$form_state
->setRebuild();
}
}
elseif ($server
->hasValidBackend()) {
$backend = $server
->getBackend();
if ($backend instanceof PluginFormInterface) {
$backend_form_state = SubformState::createForSubform($form['backend_config'], $form, $form_state);
$backend
->validateConfigurationForm($form['backend_config'], $backend_form_state);
}
}
}