function search_api_page_admin_edit in Search API Pages 7
Displays a form for editing or deleting a search page.
1 string reference to 'search_api_page_admin_edit'
- search_api_page_menu in ./
search_api_page.module - Implements hook_menu().
File
- ./
search_api_page.admin.inc, line 302 - Admin page callbacks for the Search pages module.
Code
function search_api_page_admin_edit(array $form, array &$form_state, Entity $page) {
$index = search_api_index_load($page->index_id);
$form_state['page'] = $page;
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Search name'),
'#maxlength' => 50,
'#required' => TRUE,
'#default_value' => $page->name,
);
$form['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled'),
'#description' => t('This will only take effect if the selected index is also enabled.'),
'#default_value' => $page->enabled,
'#disabled' => !$index->enabled,
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Search description'),
'#default_value' => $page->description,
);
$form['index'] = array(
'#type' => 'item',
'#title' => t('Index'),
'#description' => l($index->name, 'admin/config/search/search_api/index/' . $index->machine_name),
);
$form['path'] = array(
'#type' => 'textfield',
'#title' => t('Path'),
'#description' => t('Set the path under which the search page will be accessible, when enabled.'),
'#maxlength' => 50,
'#default_value' => $page->path,
);
if ($index->enabled) {
$modes = array();
foreach ($index
->query()
->parseModes() as $mode => $info) {
$modes[$mode] = $info['name'];
}
}
else {
$modes = array();
$modes['direct'] = array(
'name' => t('Direct query'),
'description' => t("Don't parse the query, just hand it to the search server unaltered. " . "Might fail if the query contains syntax errors in regard to the specific server's query syntax."),
);
$modes['single'] = array(
'name' => t('Single term'),
'description' => t('The query is interpreted as a single keyword, maybe containing spaces or special characters.'),
);
$modes['terms'] = array(
'name' => t('Multiple terms'),
'description' => t('The query is interpreted as multiple keywords seperated by spaces. ' . 'Keywords containing spaces may be "quoted". Quoted keywords must still be seperated by spaces.'),
);
}
$form['options']['#tree'] = TRUE;
$form['options']['mode'] = array(
'#type' => 'select',
'#title' => t('Query type'),
'#description' => t('Select how the query will be parsed.'),
'#options' => $modes,
'#default_value' => $page->options['mode'],
);
$fields = array();
$index_fields = $index
->getFields();
foreach ($index
->getFulltextFields() as $name) {
$fields[$name] = $index_fields[$name]['name'];
}
if (count($fields) > 1) {
$form['options']['fields'] = array(
'#type' => 'select',
'#title' => t('Searched fields'),
'#description' => t('Select the fields that will be searched. If no fields are selected, all available fulltext fields will be searched.'),
'#options' => $fields,
'#size' => min(4, count($fields)),
'#multiple' => TRUE,
'#default_value' => $page->options['fields'],
);
}
else {
$form['options']['fields'] = array(
'#type' => 'value',
'#value' => array(),
);
}
$max_length = 128;
if (isset($page->options['max_length'])) {
$max_length = $page->options['max_length'] > 0 ? $page->options['max_length'] : NULL;
}
$form['options']['max_length'] = array(
'#type' => 'textfield',
'#title' => t('Maximum keywords length'),
'#description' => t('The maximum number of characters that should be allowed as search keywords. Set to an empty string to not have any limit.'),
'#element_validate' => array(
'element_validate_integer_positive',
),
'#default_value' => $max_length,
);
$form['options']['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' => $page->options['per_page'],
);
$form['options']['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($page->options['result_page_search_form']) ? $page->options['result_page_search_form'] : TRUE,
);
$form['options']['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($page->options['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 ($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['options']['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($page->options['view_mode']) ? $page->options['view_mode'] : 'search_api_page_result',
);
}
else {
$form['options']['view_mode'] = array(
'#type' => 'value',
'#value' => key($view_modes),
);
}
$languages = array(
'current' => t("Current user's language"),
'default' => t('Default site language'),
);
$languages += entity_metadata_language_list();
if (count($languages) > 4) {
$form['options']['language_filter'] = array(
'#type' => 'select',
'#title' => t('Language filter'),
'#description' => t('Filter the results by language. Select none to show results independent of language.'),
'#options' => $languages,
'#multiple' => TRUE,
'#size' => min(4, count($languages)),
'#default_value' => isset($page->options['language_filter']) ? $page->options['language_filter'] : array(),
);
}
if (module_exists('search_api_spellcheck') && ($server = $index
->server()) && $server
->supportsFeature('search_api_spellcheck')) {
$form['options']['search_api_spellcheck'] = array(
'#type' => 'checkbox',
'#title' => t('Enable spell check'),
'#description' => t('Display "Did you mean … ?" above search results.'),
'#default_value' => !empty($page->options['search_api_spellcheck']),
);
}
$form['options']['empty_behavior'] = array(
'#type' => 'radios',
'#title' => t('Behavior on empty search'),
'#options' => array(
'' => t('Just show the search box'),
'results' => t('Show the first page of all available results'),
'blocks' => t("Perform an empty search but don't display any results."),
),
'#description' => t('This determines what is shown when the user first comes to the search page or submits an empty keyword string. For example if you want <a href="@url">Facet API</a> facets to show without having entered any search terms, select the "Perform an empty search …" option. If you would like a page of results displayed regardless of the presence of any search terms then select the "Show the first page …" option.', array(
'@url' => 'https://drupal.org/project/facetapi',
)),
'#default_value' => empty($page->options['empty_behavior']) ? '' : $page->options['empty_behavior'],
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save changes'),
);
if ($page
->hasStatus(ENTITY_OVERRIDDEN)) {
$form['actions']['revert'] = array(
'#type' => 'fieldset',
'#title' => t('Revert search page'),
'#description' => t('This will revert all settings on this search page back to the defaults. This action cannot be undone.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'revert' => array(
'#type' => 'submit',
'#value' => t('Revert search page'),
),
);
}
elseif ($page
->hasStatus(ENTITY_CUSTOM)) {
$form['actions']['delete'] = array(
'#type' => 'fieldset',
'#title' => t('Delete search page'),
'#description' => t('This will delete the search page along with all of its settings.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'delete' => array(
'#type' => 'submit',
'#value' => t('Delete search page'),
),
);
}
return $form;
}