You are here

function search_by_page_admin_overview in Search by Page 8

Same name and namespace in other branches
  1. 6 search_by_page.module \search_by_page_admin_overview()
  2. 7 search_by_page.module \search_by_page_admin_overview()

Returns the admin overview page for module configuration.

This page lets you choose and configure search environments.

1 string reference to 'search_by_page_admin_overview'
search_by_page_menu in ./search_by_page.module
Implements hook_menu().

File

./search_by_page.module, line 1011
Main module file for Drupal module Search by Page.

Code

function search_by_page_admin_overview($form, &$form_state) {
  $form['general_sbp'] = [
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => -20,
    '#title' => t('Additional actions'),
  ];
  $form['general_sbp']['info'] = [
    '#type' => 'markup',
    '#weight' => 20,
    '#markup' => '<p>' . l(t('Configure general search settings and see indexing status'), 'admin/config/search/settings') . '</p>',
  ];
  $form['general_sbp']['cron'] = [
    '#type' => 'markup',
    '#weight' => 21,
    '#markup' => '<p>' . l(t('Visit the Status Report page to check cron status and run cron'), 'admin/reports/status') . '</p>',
  ];
  $form['general_sbp']['reset_blank'] = [
    '#type' => 'markup',
    '#weight' => 22,
    '#markup' => '<p>' . l(t('Click to reset pages that are blank in the search index, so they will reindex at next cron run.'), 'admin/config/search/search_by_page/resetblank') . '</p>',
  ];

  // Make a table of existing enviornments
  $output = '<h3>' . t('Search environments') . '</h3>';
  $output .= '<p>' . l(t('Add new search environment'), 'admin/config/search/search_by_page/add') . '</p>';
  $headers = [
    t('Environment'),
    t('URL path'),
    [
      'data' => t('Operations'),
      'colspan' => 2,
    ],
  ];
  $rows = [];
  $options = [];
  $envs = search_by_page_list_environments();
  foreach ($envs as $envid) {
    $path = search_by_page_setting_get('page_path', $envid, 'search_pages');
    $envname = search_by_page_setting_get('environment_name', $envid, t('new'));
    if (\Drupal::moduleHandler()
      ->moduleExists('i18n_string')) {
      $envname = i18n_string_translate('search_by_page:environment:name' . $envid, $envname);
    }
    $options[$envid] = $envname;
    $rows[] = [
      $envname,
      l($path, $path),
      l('edit', 'admin/config/search/search_by_page/edit/' . $envid),
      l('delete', 'admin/config/search/search_by_page/delete/' . $envid),
    ];
  }
  if (!count($rows)) {
    $rows[] = [
      t('No environments defined'),
      '',
      '',
      '',
    ];
  }
  $output .= theme('table', [
    'header' => $headers,
    'rows' => $rows,
  ]);
  $form['environment_table'] = [
    '#type' => 'markup',
    '#weight' => -5,
    '#markup' => $output,
  ];

  // Form section to choose default environment, name for it in Search, and
  // cron limit.
  $arr = [
    1,
    10,
    20,
    50,
    100,
    200,
    500,
  ];
  $items = array_combine($arr, $arr);
  $core_limit = (int) \Drupal::state()
    ->get('search_cron_limit', 100);
  $limit = (int) \Drupal::state()
    ->get('search_by_page_cron_limit', $core_limit);
  $form['search_by_page_cron_limit'] = [
    '#type' => 'select',
    '#weight' => -3,
    '#default_value' => $limit,
    '#options' => $items,
    '#title' => t('Number of items to index per cron run'),
    '#description' => t('The maximum number of items indexed in each pass of a <a href="@cron">cron maintenance task</a> by Search by Page.', [
      '@cron' => url('admin/reports/status'),
    ]),
  ];
  $form['search_by_page_default_environment'] = [
    '#type' => 'select',
    '#weight' => -2,
    '#default_value' => \Drupal::state()
      ->get('search_by_page_default_environment', 1),
    '#options' => $options,
    '#title' => 'Default environment',
    '#description' => t('The default environment is used for the Search by Page tab when using the core Search page.'),
  ];
  $form['search_by_page_tabname'] = [
    '#type' => 'textfield',
    '#weight' => -1,
    '#default_value' => \Drupal::state()
      ->get('search_by_page_tabname', t('Pages')),
    '#title' => 'Search tab name',
    '#description' => t('If using Search by Page with the core Search module, the name of the tab where Search by Page results are shown.'),
  ];
  $form = system_settings_form($form);
  return $form;
}