You are here

function apachesolr_search_mlt_save_block in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr_search.admin.inc \apachesolr_search_mlt_save_block()
  2. 6.3 apachesolr_search.admin.inc \apachesolr_search_mlt_save_block()

A helper function to save MLT block data.

If passed a block delta, the function will update block settings. If it is not passed a block delta, the function will create a new block.

Parameters

array $block_settings An array containing the settings required to form: a moreLikeThis request.

int $delta The id of the block you wish to update.:

3 calls to apachesolr_search_mlt_save_block()
apachesolr_install in ./apachesolr.install
Implements hook_install().
apachesolr_search_block_save in ./apachesolr_search.module
Implements hook_block_save().
apachesolr_search_mlt_add_block_form_submit in ./apachesolr_search.admin.inc

File

./apachesolr_search.admin.inc, line 1014
Administrative settings for searching.

Code

function apachesolr_search_mlt_save_block($block_settings = array(), $delta = NULL) {
  $blocks = variable_get('apachesolr_search_mlt_blocks', array());
  if (is_null($delta)) {
    $count = 0;
    ksort($blocks);

    // Construct a new array key.
    if (end($blocks)) {
      list(, $count) = explode('-', key($blocks));
    }
    $delta = sprintf('mlt-%03d', 1 + $count);
  }
  $defaults = apachesolr_search_mlt_block_defaults();

  // Remove stray form values.
  $blocks[$delta] = array_intersect_key($block_settings, $defaults) + $defaults;

  // Eliminate non-selected fields.
  $blocks[$delta]['mlt_fl'] = array_filter($blocks[$delta]['mlt_fl']);
  $blocks[$delta]['delta'] = $delta;
  $blocks[$delta]['mlt_type_filters'] = array_filter($blocks[$delta]['mlt_type_filters']);
  $blocks[$delta]['mlt_custom_filters'] = trim($blocks[$delta]['mlt_custom_filters']);
  variable_set('apachesolr_search_mlt_blocks', $blocks);
}