You are here

function search_api_page_result_content_type_edit_form in Search API Pages 7

Returns an edit form for custom type settings.

1 string reference to 'search_api_page_result_content_type_edit_form'
search_api_page_result.inc in plugins/content_types/search_api_page_result.inc

File

plugins/content_types/search_api_page_result.inc, line 61

Code

function search_api_page_result_content_type_edit_form($form, &$form_state) {
  $conf = $form_state['conf'];
  $pages = array();
  foreach (search_api_page_load_multiple(FALSE, array(
    'enabled' => TRUE,
  )) as $info) {
    $pages[$info->machine_name] = $info->name;
  }
  if (!empty($conf['page'])) {
    $info = search_api_page_load($conf['page']);
    $index = search_api_index_load($info->index_id);
  }
  $form['page'] = array(
    '#type' => 'select',
    '#title' => t('Search API Page'),
    '#options' => $pages,
    '#default_value' => $conf['page'],
    '#required' => TRUE,
  );
  $form['per_page'] = array(
    '#type' => 'select',
    '#title' => t('Results per page'),
    '#description' => t('Select how many items will be displayed on one page of the search result.'),
    '#options' => drupal_map_assoc(array(
      5,
      10,
      20,
      30,
      40,
      50,
      60,
      80,
      100,
    )),
    '#default_value' => $conf['per_page'],
    '#required' => TRUE,
  );
  $form['result_page_search_form'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show search form on result page'),
    '#description' => t('Enable or disable the search form on the result page'),
    '#default_value' => isset($conf['result_page_search_form']) ? $conf['result_page_search_form'] : TRUE,
  );
  $form['get_per_page'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow GET override'),
    '#description' => t('Allow the „Results per page“ setting to be overridden from the URL, using the "per_page" GET parameter.<br />' . 'Example: <code>http://example.com/search_results?per_page=7</code>'),
    '#default_value' => !empty($conf['get_per_page']),
  );
  $view_modes = array(
    'search_api_page_result' => t('Themed as search results'),
  );

  // For entities, we also add all entity view modes.
  if (isset($index) && $index
    ->getEntityType()) {
    $entity_info = entity_get_info($index
      ->getEntityType());
    foreach ($entity_info['view modes'] as $mode => $mode_info) {
      $view_modes[$mode] = $mode_info['label'];
    }
  }
  if (count($view_modes) > 1) {
    $form['view_mode'] = array(
      '#type' => 'select',
      '#title' => t('View mode'),
      '#options' => $view_modes,
      '#description' => t('Select how search results will be displayed.'),
      '#size' => 1,
      '#default_value' => isset($conf['view_mode']) ? $conf['view_mode'] : 'search_api_page_result',
      '#required' => TRUE,
    );
  }
  else {
    $form['view_mode'] = array(
      '#type' => 'value',
      '#value' => key($view_modes),
    );
  }
  return $form;
}