123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- /**
- * @file
- * Core hook implementations for Search API Solr Overrides.
- */
- /**
- * Implements hook_search_api_server_load().
- *
- * Provide a configuration as the same structure as the
- * search api server entity in array form (keyed by the
- * machine name of the solr service).
- *
- * Example:
- * $conf['search_api_solr_overrides'] = array(
- * 'solr-server-id' => array(
- * 'name' => t('Solr Server (Overridden)'),
- * 'options' => array(
- * 'host' => '127.0.0.1',
- * 'port' => 8983,
- * 'path' => '/solr',
- * ),
- * ),
- * ),
- * );
- *
- * Note: This is an example as solr configurations vary.
- */
- function search_api_solr_overrides_search_api_server_load($servers) {
- // Get the solr host overrides.
- $overrides = variable_get('search_api_solr_overrides', FALSE);
- // Ensure the is information provided.
- if (empty($overrides)) {
- return;
- }
- // Loop over an make the required updates.
- foreach ($overrides as $id => $override) {
- // Check to see if the server config exists.
- if (!empty($servers[$id])) {
- foreach ($servers[$id] as $key => $field) {
- // Ensure we need to override.
- if (empty($override[$key])) {
- continue;
- }
- // Check for if the field is an array.
- if (is_array($field)) {
- $servers[$id]->$key = array_merge($servers[$id]->$key, $override[$key]);
- }
- // Else its a value.
- else {
- $servers[$id]->$key = $override[$key];
- }
- }
- }
- }
- }
|