public function SearchApiElasticsearchAbstractService::configurationFormValidate in Search API Elasticsearch 7
Overrides configurationFormValidate().
Overrides SearchApiAbstractService::configurationFormValidate
File
- includes/
SearchApiElasticsearchAbstractService.inc, line 307 - Provides a Elasticsearch-based service class for the Search API.
Class
- SearchApiElasticsearchAbstractService
- Elasticsearch service abstract class.
Code
public function configurationFormValidate(array $form, array &$values, array &$form_state) {
unset($values['add_more']);
$count_nodes = count($values);
if (module_exists('search_api_facetapi')) {
// Facet limit.
if (filter_var($values['facet_limit'], FILTER_VALIDATE_INT, array(
'options' => array(
'min_range' => 0,
),
)) === FALSE) {
form_set_error('options][form][facet_limit', t('You must enter a positive integer for the elasticsearch facet limit.'));
}
}
$options = $this
->getOptions();
foreach ($values as $i => $setting) {
if ($i != 'facet_limit') {
// Daemon IP address.
if (filter_var($values[$i]['host'], FILTER_VALIDATE_IP) === FALSE) {
form_set_error('options][form]' . $i . '[host', t('You must enter a valid IP address for the elasticsearch daemon.'));
}
// Daemon Port.
if (filter_var($values[$i]['port'], FILTER_VALIDATE_INT, array(
'options' => array(
'min_range' => 0,
'max_range' => 65535,
),
)) === FALSE) {
form_set_error('options][form]' . $i . '[port', t('You must enter a valid Port (between 0 and 65535) for the elasticsearch daemon.'));
}
$values[$i]['path'] = $this
->setPath($values[$i]['path']);
}
// Put http_user and http_password in correct form.
if (!empty($setting['headers']['http_user'])) {
// If username matches the old value and password is empty, then use the old Authentication.
if (empty($setting['headers']['http_pass'])) {
if ($setting['headers']['http_user'] == $options[$i]['headers']['http_user']) {
$values[$i]['headers']['Authorization'] = $options[$i]['headers']['Authorization'];
}
else {
form_set_error('http_pass', t('If you are changing the username, you need to supply the password.'));
return;
}
}
else {
$values[$i]['headers']['Authorization'] = 'Basic ' . base64_encode($setting['headers']['http_user'] . ':' . $setting['headers']['http_pass']);
}
}
if (isset($values[$i]['headers']['http_pass'])) {
unset($values[$i]['headers']['http_pass']);
}
// Put aws_access_key_id and aws_secret_access_keyword in correct form.
if (!empty($setting['aws']['aws_access_key_id'])) {
if (empty($setting['aws']['aws_secret_access_key'])) {
form_set_error('aws_secret_access_key', t('Access Secret Key is required to generate the Access token.'));
return;
}
if (empty($setting['aws']['aws_region'])) {
form_set_error('aws_region', t('Region of the Elasticsearch Service must be specified.'));
return;
}
}
if (isset($values[$i]['aws']['aws_access_key_id'])) {
$values[$i]['aws_access_key_id'] = $values[$i]['aws']['aws_access_key_id'];
}
if (isset($values[$i]['aws']['aws_secret_access_key'])) {
$values[$i]['aws_secret_access_key'] = $values[$i]['aws']['aws_secret_access_key'];
}
if (isset($values[$i]['aws']['aws_region'])) {
$values[$i]['aws_region'] = $values[$i]['aws']['aws_region'];
}
}
}