You are here

function elasticsearch_connector_edit_cluster in Elasticsearch Connector 7.5

Same name and namespace in other branches
  1. 7 elasticsearch_connector.admin.inc \elasticsearch_connector_edit_cluster()
  2. 7.2 elasticsearch_connector.admin.inc \elasticsearch_connector_edit_cluster()

Add/edit Elasticsearch clusters.

Parameters

object $cluster:

Return value

array $form

1 string reference to 'elasticsearch_connector_edit_cluster'
elasticsearch_connector_menu in ./elasticsearch_connector.module
Implements hook_menu().

File

./elasticsearch_connector.admin.inc, line 290
Created on Dec 23, 2013

Code

function elasticsearch_connector_edit_cluster($form, $form_state, $cluster = NULL) {
  $form = array();

  // TODO: Lock the edit of status if the cluster_id is lock by a module.
  elasticsearch_connector_set_breadcrumb(array(
    l(t('Elasticsearch Clusters'), elasticsearch_connector_main_settings_path() . '/clusters'),
  ));
  $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' => 'elasticsearch_connector_cluster_load',
    ),
    '#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'] = elasticsearch_connector_edit_cluster_form_info($cluster);
  $default = elasticsearch_connector_get_default_connector();
  $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 : ELASTICSEARCH_CONNECTOR_STATUS_ACTIVE,
    '#options' => array(
      ELASTICSEARCH_CONNECTOR_STATUS_ACTIVE => t('Active'),
      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">&nbsp;</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'] : ELASTICSEARCH_CONNECTOR_DEFAULT_TIMEOUT,
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['save'] = array(
    '#type' => 'submit',
    '#validate' => array(
      'elasticsearch_connector_edit_cluster_validate',
    ),
    '#submit' => array(
      'elasticsearch_connector_edit_cluster_submit',
    ),
    '#value' => t('Save'),
  );
  return $form;
}