You are here

public function IndexForm::buildEntityForm in Elasticsearch Connector 8.5

Same name and namespace in other branches
  1. 8.7 src/Form/IndexForm.php \Drupal\elasticsearch_connector\Form\IndexForm::buildEntityForm()
  2. 8 src/Form/IndexForm.php \Drupal\elasticsearch_connector\Form\IndexForm::buildEntityForm()
  3. 8.2 src/Form/IndexForm.php \Drupal\elasticsearch_connector\Form\IndexForm::buildEntityForm()
  4. 8.6 src/Form/IndexForm.php \Drupal\elasticsearch_connector\Form\IndexForm::buildEntityForm()
1 call to IndexForm::buildEntityForm()
IndexForm::form in src/Form/IndexForm.php
Gets the actual form array to be built.

File

src/Form/IndexForm.php, line 170

Class

IndexForm
Form controller for node type forms.

Namespace

Drupal\elasticsearch_connector\Form

Code

public function buildEntityForm(array &$form, FormStateInterface $form_state) {

  // TODO: Provide check and support for other index modules settings.
  // TODO: Provide support for the rest of the dynamic settings.
  // TODO: Make sure that on edit the static settings cannot be changed.
  // @see https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html
  $form['index'] = array(
    '#type' => 'value',
    '#value' => $this->entity,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Index name'),
    '#required' => TRUE,
    '#default_value' => '',
    '#description' => t('Enter the index name.'),
    '#weight' => 1,
  );
  $form['index_id'] = array(
    '#type' => 'machine_name',
    '#title' => t('Index id'),
    '#default_value' => '',
    '#maxlength' => 125,
    '#description' => t('Unique, machine-readable identifier for this Index'),
    '#machine_name' => array(
      'exists' => array(
        $this
          ->getIndexStorage(),
        'load',
      ),
      'source' => array(
        'name',
      ),
      'replace_pattern' => '[^a-z0-9_]+',
      'replace' => '_',
    ),
    '#required' => TRUE,
    '#disabled' => !empty($this->entity->index_id),
    '#weight' => 2,
  );

  // Here server refers to the elasticsearch cluster.
  $form['server'] = array(
    '#type' => 'radios',
    '#title' => $this
      ->t('Server'),
    '#default_value' => !empty($this->entity->server) ? $this->entity->server : $this->clusterManager
      ->getDefaultCluster(),
    '#description' => $this
      ->t('Select the server this index should reside on. Index can not be enabled without connection to valid server.'),
    '#options' => $this
      ->getClusterField('cluster_id'),
    '#weight' => 9,
    '#required' => TRUE,
  );
  $form['num_of_shards'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of shards'),
    '#required' => TRUE,
    '#default_value' => 5,
    '#description' => t('Enter the number of shards for the index.'),
    '#weight' => 3,
  );
  $form['num_of_replica'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of replica'),
    '#default_value' => 1,
    '#description' => t('Enter the number of shards replicas.'),
    '#weight' => 4,
  );
  $form['codec'] = array(
    '#type' => 'select',
    '#title' => t('Codec'),
    '#default_value' => !empty($this->entity->codec) ? $this->entity->codec : 'default',
    '#description' => t('Select compression for stored data. Defaults to: LZ4.'),
    '#options' => array(
      'default' => 'LZ4',
      'best_compression' => 'DEFLATE',
    ),
    '#weight' => 5,
  );
}