@@ -303,46 +303,42 @@ function elasticsearch_connector_edit_cluster($form, $form_state, $cluster = NUL
303
303
'#type ' => 'textfield ' ,
304
304
'#title ' => t ('Administrative cluster name ' ),
305
305
'#default_value ' => empty ($ cluster ->name ) ? '' : $ cluster ->name ,
306
- '#description ' => t ('Enter the administrative cluster name that will uniquely define your Elasticsearch cluster ' ),
306
+ '#description ' => t ('Enter the administrative cluster name that will be your Elasticsearch cluster unique identifier. ' ),
307
307
'#required ' => TRUE ,
308
308
);
309
309
310
310
$ form ['cluster_id ' ] = array (
311
311
'#type ' => 'machine_name ' ,
312
312
'#title ' => t ('Cluster id ' ),
313
+ '#default_value ' => !empty ($ cluster ->cluster_id ) ? $ cluster ->cluster_id : '' ,
314
+ '#maxlength ' => 125 ,
315
+ '#description ' => t ('A unique machine-readable name for this Elasticsearch cluster. ' ),
313
316
'#machine_name ' => array (
314
317
'exists ' => 'elasticsearch_connector_cluster_load ' ,
315
318
),
316
- '#default_value ' => !empty ($ cluster ->cluster_id ) ? $ cluster ->cluster_id : '' ,
317
- '#disabled ' => !empty ($ cluster ->cluster_id ), // Cannot change it once set.
318
- '#description ' =>
319
- t ('Unique, machine-readable identifier for this Elasticsearch environment. ' ),
320
319
'#required ' => TRUE ,
320
+ '#disabled ' => !empty ($ cluster ->cluster_id ),
321
321
);
322
322
323
323
$ form ['url ' ] = array (
324
324
'#type ' => 'textfield ' ,
325
325
'#title ' => t ('Server URL ' ),
326
326
'#default_value ' => !empty ($ cluster ->url ) ? $ cluster ->url : '' ,
327
- '#description ' => t ('Enter the URL and the port of a server (node) in the cluster. Example: http://localhost:9200. Please enter the port also even it is the default one e.g. https://localhost:443 ' ),
327
+ '#description ' => t (
328
+ 'URL and port of a server (node) in the cluster. ' .
329
+ 'Please, always enter the port even if it is default one. ' .
330
+ 'Nodes will be automatically discovered. ' .
331
+ 'Examples: http://localhost:9200 or https://localhost:443. ' ),
328
332
'#required ' => TRUE ,
329
- //'#limit_validation_errors' => array(array('url')),
330
333
);
331
334
332
- $ cluster_info = NULL ;
333
- $ form_state_active = FALSE ;
334
- if (isset ($ cluster ->url ) && empty ($ form_state ['input ' ])) {
335
- $ cluster_info = elasticsearch_connector_get_cluster_info ($ cluster );
336
- $ form_state_active = TRUE ;
337
- }
338
-
339
- $ form ['status_info ' ] = elasticsearch_connector_edit_cluster_form_info ($ cluster_info , $ form_state_active );
335
+ $ form ['status_info ' ] = elasticsearch_connector_edit_cluster_form_info ($ cluster );
340
336
341
337
$ default = elasticsearch_connector_get_default_connector ();
342
338
$ form ['default ' ] = array (
343
339
'#type ' => 'checkbox ' ,
344
340
'#title ' => t ('Make this cluster default connection ' ),
345
- '#description ' => t ('If no specific cluster connection specified the API will use the default connection. ' ),
341
+ '#description ' => t ('If the cluster connection is not specified the API will use the default connection. ' ),
346
342
'#default_value ' => (empty ($ default ) || (!empty ($ cluster ->cluster_id ) && $ cluster ->cluster_id == $ default )) ? '1 ' : '0 ' ,
347
343
);
348
344
@@ -353,8 +349,8 @@ function elasticsearch_connector_edit_cluster($form, $form_state, $cluster = NUL
353
349
$ form ['options ' ]['multiple_nodes_connection ' ] = array (
354
350
'#type ' => 'checkbox ' ,
355
351
'#title ' => t ('Use multiple nodes connection ' ),
356
- '#description ' => t ('It will automatically discover all nodes and use them in the connection to the cluster. ' .
357
- 'The Elasticsearch client can then randomise the query execution between nodes. ' ),
352
+ '#description ' => t ('Automatically discover all nodes and use them in the cluster connection . ' .
353
+ 'Then the Elasticsearch client can distribute the query execution on random base between nodes. ' ),
358
354
'#default_value ' => (!empty ($ cluster ->options ['multiple_nodes_connection ' ]) ? 1 : 0 ),
359
355
);
360
356
@@ -397,7 +393,7 @@ function elasticsearch_connector_edit_cluster($form, $form_state, $cluster = NUL
397
393
$ form ['options ' ]['username ' ] = array (
398
394
'#type ' => 'textfield ' ,
399
395
'#title ' => t ('Username ' ),
400
- '#description ' => t ('The username for the authentication. ' ),
396
+ '#description ' => t ('The username for authentication. ' ),
401
397
'#default_value ' => (!empty ($ cluster ->options ['username ' ]) ? $ cluster ->options ['username ' ] : '' ),
402
398
'#states ' => array (
403
399
'visible ' => array (
@@ -409,7 +405,7 @@ function elasticsearch_connector_edit_cluster($form, $form_state, $cluster = NUL
409
405
$ form ['options ' ]['password ' ] = array (
410
406
'#type ' => 'textfield ' ,
411
407
'#title ' => t ('Password ' ),
412
- '#description ' => t ('The password for the authentication. ' ),
408
+ '#description ' => t ('The password for authentication. ' ),
413
409
'#default_value ' => (!empty ($ cluster ->options ['password ' ]) ? $ cluster ->options ['password ' ] : '' ),
414
410
'#states ' => array (
415
411
'visible ' => array (
@@ -424,7 +420,7 @@ function elasticsearch_connector_edit_cluster($form, $form_state, $cluster = NUL
424
420
'#size ' => 20 ,
425
421
'#required ' => TRUE ,
426
422
'#element_validate ' => array ('element_validate_number ' ),
427
- '#description ' => t ('The seconds in which the connection will timeout if no connection with Elasticsearch. ' ),
423
+ '#description ' => t ('After how many seconds the connection should timeout if there is no connection to Elasticsearch. ' ),
428
424
'#default_value ' => (!empty ($ cluster ->options ['timeout ' ]) ? $ cluster ->options ['timeout ' ] : ELASTICSEARCH_CONNECTOR_DEFAULT_TIMEOUT ),
429
425
);
430
426
@@ -598,50 +594,66 @@ function elasticsearch_connector_cluster_indices_add_submit($form, &$form_state)
598
594
* @param bool $ajax
599
595
* @return array
600
596
*/
601
- function elasticsearch_connector_edit_cluster_form_info ($ cluster_info = NULL , $ ajax = NULL ) {
602
- $ headers = array (
603
- array ('data ' => t ('Cluster name ' )),
604
- array ('data ' => t ('Status ' )),
605
- array ('data ' => t ('Number of nodes ' )),
606
- );
607
-
608
- $ rows = $ element = array ();
609
-
610
- if (isset ($ cluster_info ['state ' ])) {
611
- $ rows = array (array (
612
- $ cluster_info ['health ' ]['cluster_name ' ],
613
- $ cluster_info ['health ' ]['status ' ],
614
- $ cluster_info ['health ' ]['number_of_nodes ' ],
615
- ));
616
-
617
- $ element = array (
618
- '#theme ' => 'table ' ,
619
- '#header ' => $ headers ,
620
- '#rows ' => $ rows ,
621
- '#attributes ' => array (
622
- 'class ' => array ('admin-elasticsearch-connector ' ),
623
- 'id ' => 'cluster-info ' ),
624
- );
625
- }
626
- elseif (!empty ($ ajax )) {
627
- $ rows = array (array (
628
- t ('Unknown ' ),
629
- t ('Unavailable ' ),
630
- '' ,
631
- ));
597
+ function elasticsearch_connector_edit_cluster_form_info ($ cluster ) {
598
+ $ element = array ();
632
599
633
- $ element = array (
634
- '#theme ' => 'table ' ,
635
- '#header ' => $ headers ,
636
- '#rows ' => $ rows ,
637
- '#attributes ' => array (
638
- 'class ' => array ('admin-elasticsearch-connector ' ),
639
- 'id ' => 'cluster-info ' ),
640
- );
641
- }
642
- else {
643
- $ element ['#type ' ] = 'markup ' ;
644
- $ element ['#markup ' ] = '<div id="cluster-info"> </div> ' ;
600
+ if (isset ($ cluster ->url )) {
601
+ try {
602
+ $ cluster_info = elasticsearch_connector_get_cluster_info ($ cluster );
603
+ if ($ cluster_info ) {
604
+ $ headers = array (
605
+ array ('data ' => t ('Cluster name ' )),
606
+ array ('data ' => t ('Status ' )),
607
+ array ('data ' => t ('Number of nodes ' )),
608
+ );
609
+
610
+ if (isset ($ cluster_info ['state ' ])) {
611
+ $ rows = array (
612
+ array (
613
+ $ cluster_info ['health ' ]['cluster_name ' ],
614
+ $ cluster_info ['health ' ]['status ' ],
615
+ $ cluster_info ['health ' ]['number_of_nodes ' ],
616
+ )
617
+ );
618
+
619
+ $ element = array (
620
+ '#theme ' => 'table ' ,
621
+ '#header ' => $ headers ,
622
+ '#rows ' => $ rows ,
623
+ '#attributes ' => array (
624
+ 'class ' => array ('admin-elasticsearch-connector ' ),
625
+ 'id ' => 'cluster-info '
626
+ ),
627
+ );
628
+ }
629
+ else {
630
+ $ rows = array (
631
+ array (
632
+ t ('Unknown ' ),
633
+ t ('Unavailable ' ),
634
+ '' ,
635
+ )
636
+ );
637
+
638
+ $ element = array (
639
+ '#theme ' => 'table ' ,
640
+ '#header ' => $ headers ,
641
+ '#rows ' => $ rows ,
642
+ '#attributes ' => array (
643
+ 'class ' => array ('admin-elasticsearch-connector ' ),
644
+ 'id ' => 'cluster-info '
645
+ ),
646
+ );
647
+ }
648
+ }
649
+ else {
650
+ $ element ['#type ' ] = 'markup ' ;
651
+ $ element ['#markup ' ] = '<div id="cluster-info"> </div> ' ;
652
+ }
653
+ }
654
+ catch (\Exception $ e ) {
655
+ drupal_set_message ($ e ->getMessage (), 'error ' );
656
+ }
645
657
}
646
658
647
659
return $ element ;
0 commit comments