Skip to main content
Added clarification
Source Link

This code resolved my need to backport production enabled-facet settings into localhost. Features are not used. tfk_search is the name of my module, substitute this for your own.

/**
 * Implement hook_form_FORM_ID_alter().
 *
 * Alter apachesolr_enabled_facets_form(), add an additional submit handler
 * that helps us export enabled facet settings via Features.
 */
function tfk_search_form_apachesolr_enabled_facets_form_alter(&$form, &$form_state, $form_id) {
  $form['#submit'][] = 'tfk_search_enabled_facets_form_submit';
}

/**
 * An additional submit handler for the active facets form.
 *
 * Save current settings into default server. Allows backporting
 * production settings into localhost. No Feature revert needed.
 *
 * @see apachesolr_enabled_facets_form
 */
function tfk_search_enabled_facets_form_submit($form, &$form_state) {
  $enabled = array();
  foreach ($form_state['values']['apachesolr_enabled_facets'] as $module => $facets) {
    $enabled[$module] = array_filter($facets);
  }
  
  // We hardcode 'solr' here because apachesolr_default_server() resolves to something
  // else in production.
  apachesolr_save_enabled_facets('solr', $enabled);
}

After importing the database from production into local, while your default Solr instance is still the same as the one in production, go the enabled-facet settings page, and save it (even if you make no changes on it). Then switch the default Solr instance to the local one (solr). It should automatically pick up the facet settings for production.

Note that this solution is good for backporting settings, but not for exporting them á la Features. It would not work if you wanted to automatically push these settings into various sites.

This code resolved my need to backport production enabled-facet settings into localhost. Features are not used. tfk_search is the name of my module, substitute this for your own.

/**
 * Implement hook_form_FORM_ID_alter().
 *
 * Alter apachesolr_enabled_facets_form(), add an additional submit handler
 * that helps us export enabled facet settings via Features.
 */
function tfk_search_form_apachesolr_enabled_facets_form_alter(&$form, &$form_state, $form_id) {
  $form['#submit'][] = 'tfk_search_enabled_facets_form_submit';
}

/**
 * An additional submit handler for the active facets form.
 *
 * Save current settings into default server. Allows backporting
 * production settings into localhost. No Feature revert needed.
 *
 * @see apachesolr_enabled_facets_form
 */
function tfk_search_enabled_facets_form_submit($form, &$form_state) {
  $enabled = array();
  foreach ($form_state['values']['apachesolr_enabled_facets'] as $module => $facets) {
    $enabled[$module] = array_filter($facets);
  }
  
  // We hardcode 'solr' here because apachesolr_default_server() resolves to something
  // else in production.
  apachesolr_save_enabled_facets('solr', $enabled);
}

This code resolved my need to backport production enabled-facet settings into localhost. Features are not used. tfk_search is the name of my module, substitute this for your own.

/**
 * Implement hook_form_FORM_ID_alter().
 *
 * Alter apachesolr_enabled_facets_form(), add an additional submit handler
 * that helps us export enabled facet settings via Features.
 */
function tfk_search_form_apachesolr_enabled_facets_form_alter(&$form, &$form_state, $form_id) {
  $form['#submit'][] = 'tfk_search_enabled_facets_form_submit';
}

/**
 * An additional submit handler for the active facets form.
 *
 * Save current settings into default server. Allows backporting
 * production settings into localhost. No Feature revert needed.
 *
 * @see apachesolr_enabled_facets_form
 */
function tfk_search_enabled_facets_form_submit($form, &$form_state) {
  $enabled = array();
  foreach ($form_state['values']['apachesolr_enabled_facets'] as $module => $facets) {
    $enabled[$module] = array_filter($facets);
  }
  
  // We hardcode 'solr' here because apachesolr_default_server() resolves to something
  // else in production.
  apachesolr_save_enabled_facets('solr', $enabled);
}

After importing the database from production into local, while your default Solr instance is still the same as the one in production, go the enabled-facet settings page, and save it (even if you make no changes on it). Then switch the default Solr instance to the local one (solr). It should automatically pick up the facet settings for production.

Note that this solution is good for backporting settings, but not for exporting them á la Features. It would not work if you wanted to automatically push these settings into various sites.

Source Link

This code resolved my need to backport production enabled-facet settings into localhost. Features are not used. tfk_search is the name of my module, substitute this for your own.

/**
 * Implement hook_form_FORM_ID_alter().
 *
 * Alter apachesolr_enabled_facets_form(), add an additional submit handler
 * that helps us export enabled facet settings via Features.
 */
function tfk_search_form_apachesolr_enabled_facets_form_alter(&$form, &$form_state, $form_id) {
  $form['#submit'][] = 'tfk_search_enabled_facets_form_submit';
}

/**
 * An additional submit handler for the active facets form.
 *
 * Save current settings into default server. Allows backporting
 * production settings into localhost. No Feature revert needed.
 *
 * @see apachesolr_enabled_facets_form
 */
function tfk_search_enabled_facets_form_submit($form, &$form_state) {
  $enabled = array();
  foreach ($form_state['values']['apachesolr_enabled_facets'] as $module => $facets) {
    $enabled[$module] = array_filter($facets);
  }
  
  // We hardcode 'solr' here because apachesolr_default_server() resolves to something
  // else in production.
  apachesolr_save_enabled_facets('solr', $enabled);
}