function search_by_page_admin_settings in Search by Page 8
Same name and namespace in other branches
- 6 search_by_page.module \search_by_page_admin_settings()
- 7 search_by_page.module \search_by_page_admin_settings()
Returns the admin settings page for a single search environment.
Besides some general settings for the modules as a whole, also includes all sub-modules' hook_search_by_page_settings() return values.
Parameters
$environment: ID of environment for this settings page, or zero to add a new one.
1 string reference to 'search_by_page_admin_settings'
- search_by_page_menu in ./
search_by_page.module - Implements hook_menu().
File
- ./
search_by_page.module, line 1132 - Main module file for Drupal module Search by Page.
Code
function search_by_page_admin_settings($form, &$form_state, $environment = 0) {
// We need a non-zero environment number (0 indicates adding a new one)
$environment = intval($environment);
if (!$environment) {
$envs = search_by_page_list_environments();
$max = 0;
foreach ($envs as $env) {
if ($env > $max) {
$max = $env;
}
}
$environment = $max + 1;
}
$form['environment'] = [
'#type' => 'value',
'#value' => $environment,
];
$form['general_env'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#weight' => -99,
'#title' => t('General settings for this environment'),
];
$form['general_env']['environment_name'] = [
'#type' => 'textfield',
'#weight' => 0,
'#title' => t('Environment name (shown to administrators only)'),
'#default_value' => search_by_page_setting_get('environment_name', $environment, t('new')),
];
$form['general_env']['set_as_default'] = [
'#type' => 'checkbox',
'#weight' => 1,
'#title' => t('Set this environment as default'),
'#description' => t('The default environment is used for the Search by Page tab when using the core Search page.'),
];
if (\Drupal::state()
->get('search_by_page_default_environment', 0) == $environment) {
$form['general_env']['set_as_default']['#default_value'] = 1;
}
$form['general_env']['page_title'] = [
'#type' => 'textfield',
'#weight' => 3,
'#title' => t('Title for search page'),
'#default_value' => search_by_page_setting_get('page_title', $environment, t('Search')),
];
$form['general_env']['block_title'] = [
'#type' => 'textfield',
'#weight' => 4,
'#title' => t('Title for search block'),
'#default_value' => search_by_page_setting_get('block_title', $environment, t('Search')),
];
$form['general_env']['field_label'] = [
'#type' => 'textfield',
'#weight' => 5,
'#title' => t('Label for keywords field in search form'),
'#default_value' => search_by_page_setting_get('field_label', $environment, t('Search for')),
];
$form['general_env']['button_label'] = [
'#type' => 'textfield',
'#weight' => 6,
'#title' => t('Text on button in search form'),
'#default_value' => search_by_page_setting_get('button_label', $environment, t('Search')),
];
if (\Drupal::moduleHandler()
->moduleExists('locale')) {
$form['general_env']['labelhelp'] = [
'#type' => 'markup',
'#weight' => 8,
'#markup' => '<p>' . t("Enter the text settings above in your site's default language. If you have a multi-lingual site with the Internationalization project's String Translation module installed and enabled, you can use Drupal's translation interface to translate them.") . '</p>',
];
}
$form['general_env']['page_path'] = [
'#type' => 'textfield',
'#weight' => 9,
'#title' => t('URL path for search page'),
'#description' => t('Path cannot include a /'),
'#field_prefix' => search_by_page_path_field_prefix(),
'#default_value' => search_by_page_setting_get('page_path', $environment, 'search_pages'),
];
$form['general_env']['results_per_page'] = [
'#type' => 'textfield',
'#weight' => 10,
'#title' => t('Number of search results to show per page'),
'#default_value' => search_by_page_setting_get('results_per_page', $environment, 10),
];
$form['general_env']['permhelp'] = [
'#type' => 'markup',
'#weight' => 12,
'#markup' => '<p>' . t('After creating a new environment or changing the environment name, you will need to set permissions to define who can search using this environment.') . '</p>',
];
$form['general_env']['exclude_tags'] = [
'#type' => 'textfield',
'#weight' => 15,
'#title' => t('HTML tags to exclude'),
'#description' => t('Enter the HTML tags whose <em>contents</em> should be completely removed from search indexing and search results. Separate by spaces, and just enter the tag names. Only supports letters, numbers, and underscores in tag names. Excluding h1 will exclude the page title. Example entry: script object'),
'#default_value' => search_by_page_setting_get('exclude_tags', $environment, ''),
];
$form['#submit'] = [];
$form = array_merge($form, \Drupal::moduleHandler()
->invokeAll('search_by_page_settings', $environment));
$form['buttons']['submit'] = [
'#type' => 'submit',
'#value' => t('Save configuration'),
];
$form['#submit'][] = 'search_by_page_admin_settings_submit';
$form['#theme'] = 'system_settings_form';
// Cause the update function to get called when form submits
$form['#submit'][] = '_search_by_page_rebuild_all_paths';
// Cause a translation refresh when form submits
$form['#submit'][] = '_search_by_page_refresh_translations';
return $form;
}