public function SearchApiSolrAcquiaMultiSubsBackend::buildConfigurationForm in Acquia Search Multiple Indexes 8
File
- src/
Plugin/ search_api/ backend/ SearchApiSolrAcquiaMultiSubsBackend.php, line 141
Class
- SearchApiSolrAcquiaMultiSubsBackend
- Plugin annotation @SearchApiBackend( id = "search_api_solr_acquia_multi_subs", label = @Translation("Acquia Solr Multi Sub"), description = @Translation("Index items using a specific Acquia Apache Solr search server.") )
Namespace
Drupal\acquia_search_multi_subs\Plugin\search_api\backendCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['host']['#access'] = FALSE;
$form['port']['#access'] = FALSE;
$form['path']['#access'] = FALSE;
// Define the override form.
$form['acquia_override_subscription'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('Configure Acquia Search'),
'#collapsed' => FALSE,
'#collapsible' => TRUE,
'#tree' => TRUE,
'#weight' => -10,
'#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(
'#weight' => -10,
'#type' => 'checkbox',
'#title' => $this
->t('Automatically switch when an Acquia Environment is detected'),
'#description' => $this
->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.
Make sure to <a href=":url">update your locally cached subscription information</a> if your core does not show up.', array(
':url' => Url::fromRoute('acquia_connector.refresh_status')
->toString(),
)),
'#default_value' => $this->configuration['acquia_override_subscription']['acquia_override_auto_switch'],
);
$options = array(
'default' => t('Default'),
'other' => t('Other'),
);
$subscription = \Drupal::config('acquia_connector.settings')
->get('subscription_data');
$search_cores = $subscription['heartbeat_data']['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' => $this->configuration['acquia_override_subscription']['acquia_override_selector'],
'#description' => $this
->t('Choose a search core to connect to. 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 for the
<a href=":url">Acquia Connector</a>.', array(
':url' => Url::fromRoute('acquia_connector.settings')
->toString(),
)),
'#states' => array(
'visible' => array(
':input[name*="acquia_override_auto_switch"]' => array(
'checked' => FALSE,
),
),
),
);
$options = array();
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']['local_core'] = array(
'#weight' => 10,
'#type' => 'select',
'#description' => t('Please enter the name of the search core you would like to use on your local environments, e.g. for development reasons.'),
'#title' => t('Core to use when site is running inside non-Acquia (local) environment'),
'#options' => $options,
'#default_value' => $this->configuration['acquia_override_subscription']['local_core'],
);
// Show a warning if there are not enough cores available to make the auto
// switch possible.
if (count($options) < 2) {
drupal_set_message($this
->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,
<a href=":url">refresh</a> your subscription so it pulls in the latest information to connect
to your indexes.', array(
':url' => Url::fromRoute('acquia_connector.refresh_status')
->toString(),
)), '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' => $this->configuration['acquia_override_subscription']['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' => $this->configuration['acquia_override_subscription']['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' => $this->configuration['acquia_override_subscription']['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,
),
),
),
);
return $form;
}