public function ClusterForm::buildEntityForm in Elasticsearch Connector 8
Same name and namespace in other branches
- 8.7 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::buildEntityForm()
- 8.2 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::buildEntityForm()
- 8.5 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::buildEntityForm()
- 8.6 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::buildEntityForm()
1 call to ClusterForm::buildEntityForm()
- ClusterForm::form in src/
Form/ ClusterForm.php - Gets the actual form array to be built.
File
- src/
Form/ ClusterForm.php, line 45 - Contains Drupal\elasticsearch_connector\Form.
Class
- ClusterForm
- Provides a form for the Cluster entity.
Namespace
Drupal\elasticsearch_connector\FormCode
public function buildEntityForm(array &$form, FormStateInterface $form_state, Cluster $cluster) {
$form['cluster'] = array(
'#type' => 'value',
'#value' => $cluster,
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Administrative cluster name'),
'#default_value' => empty($cluster->name) ? '' : $cluster->name,
'#description' => t('Enter the administrative cluster name that will be your Elasticsearch cluster unique identifier.'),
'#required' => TRUE,
);
$form['cluster_id'] = array(
'#type' => 'machine_name',
'#title' => t('Cluster id'),
'#default_value' => !empty($cluster->cluster_id) ? $cluster->cluster_id : '',
'#maxlength' => 125,
'#description' => t('A unique machine-readable name for this Elasticsearch cluster.'),
'#machine_name' => array(
'exists' => [
'Drupal\\elasticsearch_connector\\Entity\\Cluster',
'load',
],
'source' => array(
'name',
),
),
'#required' => TRUE,
'#disabled' => !empty($cluster->cluster_id),
);
$form['url'] = array(
'#type' => 'textfield',
'#title' => t('Server URL'),
'#default_value' => !empty($cluster->url) ? $cluster->url : '',
'#description' => t('URL and port of a server (node) in the cluster. ' . 'Please, always enter the port even if it is default one. ' . 'Nodes will be automatically discovered. ' . 'Examples: http://localhost:9200 or https://localhost:443.'),
'#required' => TRUE,
);
$form['status_info'] = $this
->clusterFormInfo($cluster);
$default = Cluster::getDefaultCluster();
$form['default'] = array(
'#type' => 'checkbox',
'#title' => t('Make this cluster default connection'),
'#description' => t('If the cluster connection is not specified the API will use the default connection.'),
'#default_value' => empty($default) || !empty($cluster->cluster_id) && $cluster->cluster_id == $default ? '1' : '0',
);
$form['options'] = array(
'#tree' => TRUE,
);
$form['options']['multiple_nodes_connection'] = array(
'#type' => 'checkbox',
'#title' => t('Use multiple nodes connection'),
'#description' => t('Automatically discover all nodes and use them in the cluster connection. ' . 'Then the Elasticsearch client can distribute the query execution on random base between nodes.'),
'#default_value' => !empty($cluster->options['multiple_nodes_connection']) ? 1 : 0,
);
$form['status'] = array(
'#type' => 'radios',
'#title' => t('Status'),
'#default_value' => isset($cluster->status) ? $cluster->status : Cluster::ELASTICSEARCH_CONNECTOR_STATUS_ACTIVE,
'#options' => array(
Cluster::ELASTICSEARCH_CONNECTOR_STATUS_ACTIVE => t('Active'),
Cluster::ELASTICSEARCH_CONNECTOR_STATUS_INACTIVE => t('Inactive'),
),
'#required' => TRUE,
);
$form['options']['use_authentication'] = array(
'#type' => 'checkbox',
'#title' => t('Use authentication'),
'#description' => t('Use HTTP authentication method to connect to Elasticsearch.'),
'#default_value' => !empty($cluster->options['use_authentication']) ? 1 : 0,
'#suffix' => '<div id="hosting-iframe-container"> </div>',
);
$form['options']['authentication_type'] = array(
'#type' => 'radios',
'#title' => t('Authentication type'),
'#description' => t('Select the http authentication type.'),
'#options' => array(
'Digest' => t('Digest'),
'Basic' => t('Basic'),
'NTLM' => t('NTLM'),
),
'#default_value' => !empty($cluster->options['authentication_type']) ? $cluster->options['authentication_type'] : 'Digest',
'#states' => array(
'visible' => array(
':input[name="options[use_authentication]"]' => array(
'checked' => TRUE,
),
),
),
);
$form['options']['username'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#description' => t('The username for authentication.'),
'#default_value' => !empty($cluster->options['username']) ? $cluster->options['username'] : '',
'#states' => array(
'visible' => array(
':input[name="options[use_authentication]"]' => array(
'checked' => TRUE,
),
),
),
);
$form['options']['password'] = array(
'#type' => 'textfield',
'#title' => t('Password'),
'#description' => t('The password for authentication.'),
'#default_value' => !empty($cluster->options['password']) ? $cluster->options['password'] : '',
'#states' => array(
'visible' => array(
':input[name="options[use_authentication]"]' => array(
'checked' => TRUE,
),
),
),
);
$form['options']['timeout'] = array(
'#type' => 'textfield',
'#title' => t('Connection timeout'),
'#size' => 20,
'#required' => TRUE,
'#element_validate' => array(
'element_validate_number',
),
'#description' => t('After how many seconds the connection should timeout if there is no connection to Elasticsearch.'),
'#default_value' => !empty($cluster->options['timeout']) ? $cluster->options['timeout'] : Cluster::ELASTICSEARCH_CONNECTOR_DEFAULT_TIMEOUT,
);
}