You are here

function acquia_search_multi_subs_get_settings_form in Acquia Search Multiple Indexes 7

Same name and namespace in other branches
  1. 8 acquia_search_multi_subs.common.inc \acquia_search_multi_subs_get_settings_form()

Form constructor for configuring the Solr server switch.

Used by SearchApiAcquiaSearchMultiService::configurationForm() and acquia_search_multi_subs_form_apachesolr_environment_edit_form_alter() to add these options in the appropriate place for the different modules.

Parameters

array $form: The existing form's array, passed as a reference to be appended to.

array $form_state: The form's current state.

array $configuration: The existing configuration for this environment/server.

2 calls to acquia_search_multi_subs_get_settings_form()
acquia_search_multi_subs_form_apachesolr_environment_edit_form_alter in lib/Drupal/Apachesolr/acquia_search_multi_subs.apachesolr.inc
Implements hook_form_FORM_ID_alter() for apachesolr_environment_edit_form().
SearchApiAcquiaSearchMultiService::configurationForm in lib/Drupal/SearchApiSolr/SearchApiAcquiaSearchMultiService.php
Overrides SearchApiAcquiaSearchService::configurationForm().

File

./acquia_search_multi_subs.common.inc, line 135
Helper functions used for the integration with either Solr module.

Code

function acquia_search_multi_subs_get_settings_form(array &$form, array &$form_state, array $configuration) {

  // Fill in defaults.
  $configuration += acquia_search_multi_subs_default_configuration();

  // Define the override form.
  $form['acquia_override_subscription'] = array(
    '#type' => 'fieldset',
    '#title' => t('Configure Acquia Search'),
    '#description' => t('This is usually not necessary unless you really want this search environment to connect to a different Acquia search subscription. By default it uses your subscription that was configured in the <a href="@url">Acquia Agent</a>.', array(
      '@url' => url('admin/config/system/acquia-agent'),
    )),
    '#collapsed' => FALSE,
    '#collapsible' => TRUE,
    '#tree' => TRUE,
    '#weight' => 11,
    '#element_validate' => array(
      'acquia_search_multi_subs_form_validate',
    ),
  );

  // Add a checkbox to auto switch per environment.
  $form['acquia_override_subscription']['acquia_override_auto_switch'] = array(
    '#type' => 'checkbox',
    '#title' => t('Automatically switch when an Acquia Environment is detected'),
    '#description' => t('Based on the detection of the AH_SITE_NAME and AH_SITE_ENVIRONMENT header we can detect which environment you are currently using and switch the Acquia Search Core automatically if there is a corresponding core.'),
    '#default_value' => $configuration['acquia_override_auto_switch'],
  );

  // Add a form element to make it easier to choose from multiple cores.
  $options = array(
    'default' => t('Default'),
    'other' => t('Other'),
  );
  $search_cores = acquia_search_multi_subs_get_search_cores();
  $failover_exists = NULL;
  $failover_region = NULL;
  if (is_array($search_cores)) {
    foreach ($search_cores as $search_core) {
      $options[$search_core['core_id']] = $search_core['core_id'];
      if (strstr($search_core['core_id'], '.failover')) {
        $failover_exists = TRUE;
        $matches = array();
        preg_match("/^([^-]*)/", $search_core['balancer'], $matches);
        $failover_region = reset($matches);
      }
    }
  }
  $form['acquia_override_subscription']['acquia_override_selector'] = array(
    '#type' => 'select',
    '#title' => t('Acquia Search Core'),
    '#options' => $options,
    '#default_value' => $configuration['acquia_override_selector'],
    '#description' => t('Choose any of the available search cores or manually define one by choosing "other". To use the default settings, select default.'),
    '#states' => array(
      'visible' => array(
        ':input[name*="acquia_override_auto_switch"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );

  // Show a warning if there are not enough cores available to make the auto
  // switch possible.
  if (count($options) <= 2) {
    $t_args = array(
      '!refresh' => l(t('refresh'), 'admin/config/system/acquia-search-multi-subs/refresh-status', array(
        'query' => array(
          'destination' => current_path(),
        ),
      )),
    );
    drupal_set_message(t('It seems you only have 1 Acquia Search index. To find out if you are eligible for a search core per environment it is recommended you open a support ticket with Acquia. Once you have that settled, !refresh your subscription so it pulls in the latest information to connect to your indexes.', $t_args), 'warning', FALSE);
  }

  // Generate the custom form.
  $form['acquia_override_subscription']['acquia_override_subscription_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter your Acquia Subscription Identifier'),
    '#description' => t('Prefilled with the identifier of the Acquia Connector. You can find your details in Acquia Insight.'),
    '#default_value' => $configuration['acquia_override_subscription_id'],
    '#states' => array(
      'visible' => array(
        ':input[name*="acquia_override_selector"]' => array(
          'value' => 'other',
        ),
        ':input[name*="acquia_override_auto_switch"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $form['acquia_override_subscription']['acquia_override_subscription_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter your Acquia Subscription key'),
    '#description' => t('Prefilled with the key of the Acquia Connector. You can find your details in Acquia Insight.'),
    '#default_value' => $configuration['acquia_override_subscription_key'],
    '#states' => array(
      'visible' => array(
        ':input[name*="acquia_override_selector"]' => array(
          'value' => 'other',
        ),
        ':input[name*="acquia_override_auto_switch"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $form['acquia_override_subscription']['acquia_override_subscription_corename'] = array(
    '#type' => 'textfield',
    '#description' => t('Please enter the name of the Acquia Search core you want to connect to that belongs to the above identifier and key. In most cases you would want to use the dropdown list to get the correct value.'),
    '#title' => t('Enter your Acquia Search Core Name'),
    '#default_value' => $configuration['acquia_override_subscription_corename'],
    '#states' => array(
      'visible' => array(
        ':input[name*="acquia_override_selector"]' => array(
          'value' => 'other',
        ),
        ':input[name*="acquia_override_auto_switch"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );

  // Check if we have MR cores.
  if ($failover_exists) {

    // Add a checkbox to auto switch to the failover variant in a defined region.
    $t_args = array(
      '%region' => $failover_region,
      '@import' => url('https://github.com/acquia/acquia-search-service-import'),
      '@export' => url('https://github.com/acquia/acquia-search-service-import'),
    );
    $form['acquia_override_subscription']['acquia_override_failover'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable multi-region failover support.'),
      '#description' => t('If the Drupal site is hosted in %region it will fail over to the fail-over index. You still need to use the Acquia Search Service <a href="@export">Export</a> and <a href="@import">Import</a> tools to sync your Acquia Search index between the two.', $t_args),
      '#default_value' => $configuration['acquia_override_failover'],
      '#states' => array(
        'visible' => array(
          ':input[name*="acquia_override_auto_switch"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }
}