function apachesolr_search_page_settings_form in Apache Solr Search 6.3
Same name and namespace in other branches
- 8 apachesolr_search.admin.inc \apachesolr_search_page_settings_form()
- 7 apachesolr_search.admin.inc \apachesolr_search_page_settings_form()
Menu callback/form-builder for the form to create or edit a search page.
1 string reference to 'apachesolr_search_page_settings_form'
- apachesolr_search_menu in ./
apachesolr_search.module - Implements hook_menu().
File
- ./
apachesolr_search.admin.inc, line 203 - Administrative settings for searching.
Code
function apachesolr_search_page_settings_form(&$form_state, $search_page = NULL) {
$form = array();
$environments = apachesolr_load_all_environments();
$options = array(
'' => t('<Disabled>'),
);
foreach ($environments as $id => $environment) {
$options[$id] = $environment['name'];
}
// Validate the env_id.
if (!empty($search_page['env_id']) && !apachesolr_environment_load($search_page['env_id'])) {
$search_page['env_id'] = '';
}
// Initializes form with common settings.
$form['search_page'] = array(
'#type' => 'value',
'#value' => $search_page,
);
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#description' => t('The human-readable name of the search page configuration.'),
'#required' => TRUE,
'#size' => 30,
'#maxlength' => 32,
'#default_value' => !empty($search_page['label']) ? $search_page['label'] : '',
);
if (empty($search_page['page_id'])) {
$key = '#default_value';
$disabled = FALSE;
}
else {
$key = '#value';
$disabled = TRUE;
}
$form['page_id'] = array(
'#type' => 'textfield',
'#title' => t('Page ID'),
'#description' => t('A unique machine-readable identifier for the search page configuration. It must only contain lowercase letters, numbers, and underscores.'),
'#required' => TRUE,
'#size' => 30,
'#maxlength' => 32,
$key => $search_page['page_id'],
'#disabled' => $disabled,
);
$form['description_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Description'),
'#default_value' => !empty($search_page['description']) ? TRUE : FALSE,
);
$form['description'] = array(
'#type' => 'textfield',
'#title' => t('Provide description'),
'#title_display' => 'invisible',
'#size' => 64,
'#default_value' => !empty($search_page['description']) ? $search_page['description'] : '',
'#dependency' => array(
'edit-description-enable' => array(
1,
),
),
);
$is_default = FALSE;
if (!empty($search_page)) {
$is_default = $search_page['page_id'] == apachesolr_search_default_search_page();
}
$form['make_default'] = array(
'#type' => 'checkbox',
'#title' => t('Make this Solr Search Page the default'),
'#description' => t('Useful for eg. making facets to link to this page when they are shown on non-search pages'),
'#default_value' => $is_default,
'#disabled' => $is_default,
);
$form['info'] = array(
'#title' => t('Search Page Information'),
'#type' => 'fieldset',
'#collapsible' => FALSE,
'#prefix' => '<div id="dynamic-search-page">',
'#suffix' => '</div>',
);
$core_search = FALSE;
if (!empty($search_page['page_id']) && $search_page['page_id'] == 'core_search') {
$core_search = TRUE;
}
if ($core_search) {
$description = t('This page always uses the current default search environment');
}
else {
$description = t('The environment that is used by this search page. If no environment is selected, this page will be disabled.');
}
$form['info']['env_id'] = array(
'#title' => t('Search environment'),
'#type' => 'select',
'#options' => $options,
'#default_value' => !empty($search_page['env_id']) ? $search_page['env_id'] : '',
'#disabled' => $core_search,
'#description' => $description,
);
$form['info']['page_title'] = array(
'#title' => t('Title'),
'#type' => 'textfield',
'#required' => TRUE,
'#maxlength' => 255,
'#description' => 'You can use %value to place the search term in the title',
'#default_value' => !empty($search_page['page_title']) ? $search_page['page_title'] : '',
);
$search_types = apachesolr_search_load_all_search_types();
$options = array(
'custom' => t('Custom Field'),
);
foreach ($search_types as $id => $search_type) {
$options[$id] = $search_type['name'];
}
$form['info']['search_type'] = array(
'#title' => t('Search Type'),
'#type' => 'select',
'#options' => $options,
'#default_value' => !empty($search_page['settings']['apachesolr_search_search_type']) ? $search_page['settings']['apachesolr_search_search_type'] : '',
'#access' => !$core_search,
'#description' => t('Use this only when filtering on a value from the search path.
For example, select Taxonomy Term to filter on a term ID (search/taxonomy/%).'),
'#ajax' => array(
'callback' => 'apachesolr_search_ajax_search_page_default',
'wrapper' => 'dynamic-search-page',
'method' => 'replace',
),
);
// Token element validate is added to validate the specific
// tokens that are allowed
$form['info']['search_path'] = array(
'#title' => t('Path'),
'#type' => 'textfield',
'#required' => TRUE,
'#maxlength' => 255,
'#description' => t('For example: search/my-search-page. Search keywords will appear at the end of the path.'),
'#default_value' => !empty($search_page['search_path']) ? $search_page['search_path'] : '',
);
if (!$core_search) {
$form['info']['search_path']['#description'] .= ' ' . t('You can use one % to make the search page dynamic.');
}
$form['info']['custom_filter_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Custom Filter'),
'#default_value' => !empty($search_page['settings']['apachesolr_search_custom_enable']) ? TRUE : FALSE,
);
if (!$core_search) {
$additional_help_text = t('E.g. "bundle:blog, is_uid:(1 OR 2 OR %). % will be replaced by the value of % in the path"');
}
else {
$additional_help_text = t('E.g. "bundle:blog, is_uid:(1 OR 2)"');
}
$t_args = array(
'!additional_help_text' => $additional_help_text,
);
$form['info']['filters'] = array(
'#title' => t('Custom filters'),
'#type' => 'textfield',
'#required' => FALSE,
'#maxlength' => 255,
'#description' => t('A comma-separated list of lucene filter queries to apply by default.') . ' ' . $additional_help_text,
'#default_value' => !empty($search_page['settings']['fq']) ? implode(', ', $search_page['settings']['fq']) : '',
'#dependency' => array(
'edit-custom-filter-enable' => array(
1,
),
'edit-search-type' => array(
'custom',
),
),
);
$form['advanced'] = array(
'#title' => t('Advanced Search Page Options'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
// Results per page per search page
$default_value = isset($search_page['settings']['apachesolr_search_per_page']) ? $search_page['settings']['apachesolr_search_per_page'] : '10';
$form['advanced']['apachesolr_search_per_page'] = array(
'#type' => 'textfield',
'#size' => 3,
'#title' => t('Results per page'),
'#description' => t('How many items will be displayed on one page of the search result.'),
'#default_value' => $default_value,
);
// Enable/disable spellcheck on pages
$default_value = isset($search_page['settings']['apachesolr_search_spellcheck']) ? $search_page['settings']['apachesolr_search_spellcheck'] : TRUE;
$form['advanced']['apachesolr_search_spellcheck'] = array(
'#type' => 'checkbox',
'#title' => t('Enable spell check'),
'#description' => t('Display "Did you mean … ?" above search results.'),
'#default_value' => $default_value,
);
// Enable/disable search form on search page (replaced by a block perhaps)
$default_value = isset($search_page['settings']['apachesolr_search_search_box']) ? $search_page['settings']['apachesolr_search_search_box'] : TRUE;
$form['advanced']['apachesolr_search_search_box'] = array(
'#type' => 'checkbox',
'#title' => t('Enable the search box on the page'),
'#description' => t('Display a search box on the page.'),
'#default_value' => $default_value,
);
// Enable/disable search form on search page (replaced by a block perhaps)
$default_value = isset($search_page['settings']['apachesolr_search_allow_user_input']) ? $search_page['settings']['apachesolr_search_allow_user_input'] : FALSE;
$form['advanced']['apachesolr_search_allow_user_input'] = array(
'#type' => 'checkbox',
'#title' => t('Allow user input using the URL'),
'#description' => t('Allow users to use the URL for manual facetting via fq[] params (e.g. http://example.com/search/site/test?fq[]=uid:1&fq[]=tid:99). This will only work in combination with a keyword search. The recommended value is unchecked'),
'#default_value' => $default_value,
);
// Use the main search page setting as the default for new pages.
$default_value = isset($search_page['settings']['apachesolr_search_browse']) ? $search_page['settings']['apachesolr_search_browse'] : 'browse';
$form['advanced']['apachesolr_search_browse'] = _apachesolr_search_browse_form($default_value);
// Button for the corresponding actions
$form['actions']['submit'] = array(
'#type' => 'submit',
'#redirect' => 'admin/settings/apachesolr/search-pages',
'#value' => t('Save'),
'#submit' => array(
'apachesolr_search_page_settings_form_submit',
),
);
$form['actions']['submit_edit'] = array(
'#type' => 'submit',
'#value' => t('Save and edit'),
'#submit' => array(
'apachesolr_search_page_settings_form_submit',
),
);
// Cancel
$referer_uri = referer_uri();
$request_uri = request_uri();
// In case the API did not remove the query params, we remove it forcefully
$request_uri = strtok($request_uri, '?');
// Remove leading slash
$request_uri = ltrim($request_uri, '/');
$request_uri = url($request_uri, array(
'absolute' => 'true',
));
// Redirect cancel link to the search pages if the referer is the same page or
// when there is no referer.
if ($referer_uri == $request_uri || empty($referer_uri)) {
$cancel_link = url('admin/settings/apachesolr/search-pages', array(
'absolute' => TRUE,
));
}
else {
$cancel_link = $referer_uri;
}
$form['actions']['cancel'] = array(
'#type' => 'markup',
'#value' => l(t('Cancel'), $cancel_link),
);
return $form;
}