You are here

public function SearchApiElasticsearchElastica::viewSettings in Search API Elasticsearch 7

Overrides viewSettings().

Overrides SearchApiAbstractService::viewSettings

File

modules/elastica/includes/SearchApiElasticsearchElastica.inc, line 124
Provides Elastica client for Search API Elasticsearch.

Class

SearchApiElasticsearchElastica
Search API Elasticsearch Elastica service class.

Code

public function viewSettings() {
  $output = array();
  try {
    $health = !empty($this->elasticaClient) ? $this
      ->getClusterHealth() : NULL;
  } catch (Exception $e) {
    watchdog('Elasticsearch', check_plain($e
      ->getMessage()), array(), WATCHDOG_ERROR);
    drupal_set_message(check_plain($e
      ->getMessage()), 'error');
    drupal_set_message(t('No connection to the Elasticsearch server.'), 'error');
  }
  $output['status'] = array(
    '#type' => 'item',
    '#title' => t('Elasticsearch daemon status'),
    '#markup' => '<div class="elasticsearch-daemon-status"><em>' . (!empty($health['status']) ? 'running' : 'One or more nodes not running') . '</em></div>',
  );

  // Display settings.
  $form = $form_state = array();
  $option_form = $this
    ->configurationForm($form, $form_state);
  $option_form['#title'] = t('Elasticsearch server settings');
  $element = $this
    ->parseOptionFormElement($option_form, 'options');
  if (!empty($element)) {
    $settings = '';
    foreach ($element['option'] as $sub_element) {
      $settings .= $this
        ->viewSettingElement($sub_element);
    }
    $output['settings'] = array(
      '#type' => 'fieldset',
      '#title' => $element['label'],
    );
    $output['settings'][] = array(
      '#type' => 'markup',
      '#markup' => '<div class="elasticsearch-server-settings">' . $settings . '</div>',
    );
  }
  return $output;
}