You are here

public function SearchApiSolrAcquiaMultiSubsBackend::__construct in Acquia Search Multiple Indexes 8

File

src/Plugin/search_api/backend/SearchApiSolrAcquiaMultiSubsBackend.php, line 31

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\backend

Code

public function __construct(array $configuration, $plugin_id, array $plugin_definition, ModuleHandlerInterface $module_handler, Config $search_api_solr_settings, LanguageManagerInterface $language_manager) {

  // If we have a particular core selected, then construct the index
  // configuration accordingly.
  // Shortcut to the override configuration.
  $override = $configuration['acquia_override_subscription'];

  // If auto detection was enabled, we can ignore all other settings.
  if (!empty($override['acquia_override_auto_switch']) && $override['acquia_override_auto_switch'] == TRUE) {

    // Do the magic env specific detection here.
    $configuration['host'] = acquia_search_get_search_host();
    $configuration['path'] = '/solr/';
    $configuration['core'] = isset($_ENV['AH_SITE_ENVIRONMENT']) ? $this
      ->getEnvironmentCore() : $override['local_core'];
  }
  else {
    if (!empty($override['acquia_override_selector'])) {
      $configuration['host'] = acquia_search_get_search_host();

      // Attention! We do not need to add the core to the path, because the core property
      // will inherit the core property. @see Endpoint::getBaseUri().
      // The core property is passed in our connect method, becasue we pass
      // the configuration of this backend to the plugin.
      $configuration['path'] = '/solr/';
      $configuration['core'] = isset($_ENV['AH_SITE_ENVIRONMENT']) ? $override['acquia_override_selector'] : $override['local_core'];
    }
    else {
      if (!empty($override['acquia_override_subscription_id']) && !empty($override['acquia_override_subscription_key']) && !empty($override['acquia_override_subscription_corename'])) {

        // Manual override.
      }
      else {
        $configuration['host'] = acquia_search_get_search_host();
        $configuration['path'] = '/solr/' . \Drupal::config('acquia_connector.settings')
          ->get('identifier');
      }
    }
  }
  if ($configuration['scheme'] == 'https') {
    $configuration['port'] = 443;
  }
  else {
    $configuration['port'] = 80;
  }
  return parent::__construct($configuration, $plugin_id, $plugin_definition, $module_handler, $search_api_solr_settings, $language_manager);
}