function _elasticsearch_ec_index_process in Elasticsearch Connector 8
Same name and namespace in other branches
- 8.7 elasticsearch_connector.module \_elasticsearch_ec_index_process()
- 8.2 elasticsearch_connector.module \_elasticsearch_ec_index_process()
- 8.5 elasticsearch_connector.module \_elasticsearch_ec_index_process()
- 8.6 elasticsearch_connector.module \_elasticsearch_ec_index_process()
Build two drop downs, one for the cluster and one for the indices.
Parameters
array $element:
array $form_state:
array $form:
Return value
array $element
1 string reference to '_elasticsearch_ec_index_process'
- elasticsearch_connector_element_info in ./
elasticsearch_connector.module - Implements hook_element_info().
File
- ./
elasticsearch_connector.module, line 180 - Provides hook implementations and functions accessible from other modules.
Code
function _elasticsearch_ec_index_process(array $element, array &$form_state, array $form) {
$element['#tree'] = TRUE;
$element_id = $element['#id'];
$wrapper_id = $element_id . '-index-wrapper';
// TODO: Add icon if the cluster is OK or not.
$element['cluster_id'] = array(
'#type' => 'select',
'#id' => $element_id . '-cluster-id',
'#title' => t('Select cluster'),
'#required' => $element['#required'],
'#default_value' => isset($element['#default_value']) && is_array($element['#default_value']) && isset($element['#default_value']['cluster_id']) ? $element['#default_value']['cluster_id'] : '',
// TODO: Allow this option to be overwritten and #value if we had such.
'#description' => t('Select the cluster.'),
'#ajax' => array(
'callback' => '_elasticsearch_ec_index_ajax',
'wrapper' => $wrapper_id,
'method' => 'replace',
'effect' => 'fade',
),
);
if (!isset($element['cluster_id']['#current_path'])) {
$element['cluster_id']['#current_path'] = current_path();
}
if (empty($element['#skip_default_options'])) {
$element['#only_active'] = isset($element['#only_active']) ? $element['#only_active'] : TRUE;
$element['#empty_option'] = isset($element['#empty_option']) ? $element['#empty_option'] : TRUE;
$clusters = elasticsearch_cluster_load_all($element['#only_active'], $element['#empty_option']);
$element['cluster_id']['#options'] = $clusters;
}
// TODO: We need to handle the incomming tree name if such.
$links = array();
$index_options = array(
'' => t('Select index'),
);
if (is_array($element['#value']) && !empty($element['#value']['cluster_id'])) {
$index_options = array();
try {
$index_options = elasticsearch_get_indices_options($element['#value']['cluster_id'], TRUE);
} catch (\Exception $e) {
if (!empty($element['#throw_exp'])) {
throw $e;
}
}
$links[] = array(
'title' => t('Add index'),
'href' => 'admin/config/elasticsearch/clusters/' . $element['#value']['cluster_id'] . '/indices/add',
'attributes' => array(
'target' => '_blank',
'class' => 'ec-index-dialog',
),
'query' => array(
'render' => 'elasticsearch-dialog',
'index_element_id' => $element_id . '-index',
'cluster_element_id' => $element_id . '-cluster-id',
),
);
}
$element['index'] = array(
'#type' => 'select',
'#title' => t('Select index'),
'#id' => $element_id . '-index',
'#required' => $element['#required'],
'#default_value' => isset($element['#default_value']) && is_array($element['#default_value']) && isset($element['#default_value']['index']) ? $element['#default_value']['index'] : '',
'#description' => t('Select the index.'),
'#options' => $index_options,
'#prefix' => '<div id="' . $wrapper_id . '">',
'#suffix' => '<div class="dialog-links ' . $element['#id'] . '">' . theme('links__es_index_links', array(
'links' => $links,
'attributes' => array(
'class' => 'index-dialog-links',
),
)) . '</div></div>',
);
unset($element['#title']);
$context = array(
'form' => $form,
);
drupal_alter('ec_index_process', $element, $form_state, $context);
return $element;
}