You are here

function apachesolr_settings in Apache Solr Search 8

Same name and namespace in other branches
  1. 5.2 apachesolr.admin.inc \apachesolr_settings()
  2. 5 apachesolr.module \apachesolr_settings()
  3. 6.3 apachesolr.admin.inc \apachesolr_settings()
  4. 6 apachesolr.admin.inc \apachesolr_settings()
  5. 6.2 apachesolr.admin.inc \apachesolr_settings()
  6. 7 apachesolr.admin.inc \apachesolr_settings()

Form builder for general settings used as a menu callback.

_state

Parameters

array $form:

Return value

array Output of the system_settings_form()

1 string reference to 'apachesolr_settings'
apachesolr_menu in ./apachesolr.module
Implements hook_menu().

File

./apachesolr.admin.inc, line 343
Administrative pages for the Apache Solr framework.

Code

function apachesolr_settings(array $form, array &$form_state) {
  $form = array();
  $rows = array();

  // Environment settings
  $id = apachesolr_default_environment();
  $environments = apachesolr_load_all_environments();
  $default_environment = apachesolr_default_environment();
  apachesolr_check_facetapi();

  // Reserve a row for the default one
  $rows[$default_environment] = array();
  foreach ($environments as $environment_id => $data) {

    // Define all the Operations
    $confs = array();
    $ops = array();

    // Whenever facetapi is enabled we also enable our operation link
    if (module_exists('facetapi')) {
      $confs['facets'] = array(
        'class' => 'operation',
        'data' => l(t('Facets'), 'admin/config/search/apachesolr/settings/' . $data['env_id'] . '/facets', array(
          'query' => array(
            'destination' => current_path(),
          ),
        )),
      );
    }

    // These are our result and bias settings
    if (module_exists('apachesolr_search')) {
      $confs['result_bias'] = array(
        'class' => 'operation',
        'data' => l(t('Bias'), 'admin/config/search/apachesolr/settings/' . $data['env_id'] . '/bias', array(
          'query' => array(
            'destination' => current_path(),
          ),
        )),
      );
    }
    $confs['index'] = array(
      'class' => 'operation',
      'data' => l(t('Index'), 'admin/config/search/apachesolr/settings/' . $data['env_id'] . '/index'),
    );
    $ops['edit'] = array(
      'class' => 'operation',
      'data' => l(t('Edit'), 'admin/config/search/apachesolr/settings/' . $data['env_id'] . '/edit', array(
        'query' => array(
          'destination' => current_path(),
        ),
      )),
    );
    $ops['clone'] = array(
      'class' => 'operation',
      'data' => l(t('Clone'), 'admin/config/search/apachesolr/settings/' . $data['env_id'] . '/clone', array(
        'query' => array(
          'destination' => $_GET['q'],
        ),
      )),
    );
    $env_name = l($data['name'], 'admin/config/search/apachesolr/settings/' . $data['env_id'] . '/edit', array(
      'query' => array(
        'destination' => $_GET['q'],
      ),
    ));

    // Is this row our default environment?
    if ($environment_id == $default_environment) {
      $env_name = t('!environment <em>(Default)</em>', array(
        '!environment' => $env_name,
      ));
      $env_class_row = 'default-environment';
    }
    else {
      $env_class_row = '';
    }

    // For every non-default we add a delete link
    // Allow to revert a search environment or to delete it
    $delete_value = '';
    if (!isset($data['in_code_only'])) {
      if (isset($data['type']) && $data['type'] == 'Overridden') {
        $delete_value = array(
          'class' => 'operation',
          'data' => l(t('Revert'), 'admin/config/search/apachesolr/settings/' . $data['env_id'] . '/delete'),
        );
      }
      elseif ($environment_id != $default_environment) {
        $delete_value = array(
          'class' => 'operation',
          'data' => l(t('Delete'), 'admin/config/search/apachesolr/settings/' . $data['env_id'] . '/delete'),
        );
      }
    }
    $ops['delete'] = $delete_value;

    // When we are receiving a http POST (so the page does not show) we do not
    // want to check the statusses of any environment
    $class = '';
    if (empty($form_state['input'])) {
      $class = apachesolr_server_status($data['url'], $data['service_class']) ? 'ok' : 'error';
    }
    $headers = array(
      array(
        'data' => t('Name'),
        'colspan' => 2,
      ),
      t('URL'),
      array(
        'data' => t('Configuration'),
        'colspan' => count($confs),
      ),
      array(
        'data' => t('Operations'),
        'colspan' => count($ops),
      ),
    );
    $rows[$environment_id] = array(
      'data' => array(
        // Cells
        array(
          'class' => 'status-icon',
          'data' => '<div title="' . $class . '"><span class="element-invisible">' . $class . '</span></div>',
        ),
        array(
          'class' => $env_class_row,
          'data' => $env_name,
        ),
        check_plain($data['url']),
      ),
      'class' => array(
        drupal_html_class($class),
      ),
    );

    // Add the links to the page
    $rows[$environment_id]['data'] = array_merge($rows[$environment_id]['data'], $confs);
    $rows[$environment_id]['data'] = array_merge($rows[$environment_id]['data'], $ops);
  }
  $form['apachesolr_host_settings']['actions'] = array(
    '#markup' => '<ul class="action-links">' . drupal_render($actions) . '</ul>',
  );
  $form['apachesolr_host_settings']['table'] = array(
    '#theme' => 'table',
    '#header' => $headers,
    '#rows' => array_values($rows),
    '#attributes' => array(
      'class' => array(
        'admin-apachesolr',
      ),
    ),
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced configuration'),
    '#collapsed' => TRUE,
    '#collapsible' => TRUE,
  );
  $form['advanced']['apachesolr_set_nodeapi_messages'] = array(
    '#type' => 'radios',
    '#title' => t('Extra help messages for administrators'),
    '#description' => t('Adds notices to a page whenever Drupal changed content that needs reindexing'),
    '#default_value' => variable_get('apachesolr_set_nodeapi_messages', 1),
    '#options' => array(
      0 => t('Disabled'),
      1 => t('Enabled'),
    ),
  );

  // Number of Items to index
  $numbers = drupal_map_assoc(array(
    1,
    5,
    10,
    20,
    50,
    100,
    200,
  ));
  $default_cron_limit = variable_get('apachesolr_cron_limit', 50);

  // apachesolr_cron_limit may be overridden in settings.php. If its current
  // value is not among the default set of options, add it.
  if (!isset($numbers[$default_cron_limit])) {
    $numbers[$default_cron_limit] = $default_cron_limit;
  }
  $form['advanced']['apachesolr_cron_limit'] = array(
    '#type' => 'select',
    '#title' => t('Number of items to index per cron run'),
    '#default_value' => $default_cron_limit,
    '#options' => $numbers,
    '#description' => t('Reduce the number of items to prevent timeouts and memory errors while indexing.', array(
      '@cron' => url('admin/reports/status'),
    )),
  );
  $options = array(
    'apachesolr:show_error' => t('Show error message'),
  );
  $system_info = system_get_info('module');
  if (module_exists('search')) {
    foreach (search_get_info() as $module => $search_info) {

      // Don't allow apachesolr to return results on failure of apachesolr.
      if ($module == 'apachesolr_search') {
        continue;
      }
      $options[$module] = t('Show @name search results', array(
        '@name' => $system_info[$module]['name'],
      ));
    }
  }
  $options['apachesolr:show_no_results'] = t('Show no results');
  $form['advanced']['apachesolr_failure'] = array(
    '#type' => 'select',
    '#title' => t('On failure'),
    '#options' => $options,
    '#default_value' => variable_get('apachesolr_failure', 'apachesolr:show_error'),
  );
  return system_settings_form($form);
}