function sbp_attach_sbp_settings in Search by Page 7
Same name and namespace in other branches
- 6 sbp_attach.module \sbp_attach_sbp_settings()
Implements Search by Page hook_sbp_settings().
Adds a node type selection form to the Search by Page settings page, and some options related to presentation.
File
- ./
sbp_attach.module, line 372 - Module file for Search by Page Attachments, a sub-module for Search by Page.
Code
function sbp_attach_sbp_settings($environment) {
$form = array();
$form['sbp_attach'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#weight' => -70,
'#title' => t('Attachments'),
);
// Explanation
$form['sbp_attach']['explain'] = array(
'#type' => 'markup',
'#value' => '<p>' . t('Search by Page Attachments indexes file attachments on your content types for searching. The attachments are added to content types via the core File field or similar fields. Choose the content types you want to index attachments of below, and also choose which fields you would like to index.') . '</p>',
'#weight' => -10,
);
$form['sbp_attach']['explain2'] = array(
'#type' => 'markup',
'#value' => '<p>' . t('You must choose at least one content type to index, and at least one field type, or no attachments will be indexed. Clear all content and field types or disable the Search by Page Attachments module to stop indexing file attachments.') . '</p>',
'#weight' => -9,
);
// Which node types to index attachments for
$form['sbp_attach']['sbp_attach_node_types'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Content types to index attachments of'),
'#default_value' => search_by_page_setting_get('sbp_attach_node_types', $environment, array()),
'#options' => node_type_get_names(),
'#description' => t('Choose the content types whose file field attachments you would like to have indexed by Search by Page. Use the Control or Command key to select multiple types or undo your selections.'),
'#weight' => 0,
);
// Which field types to index.
// Note: Don't check for File type itself - leave it open to other
// field modules that use 'fid', and let the user decide
$fields = field_info_fields();
$opts = array();
foreach ($fields as $field) {
$columns = $field['columns'];
// See if this field has an 'fid' column. Assume it's a potential file
// field if so.
if (isset($field['columns']['fid'])) {
$name = check_plain($field['field_name']);
$opts[$name] = check_plain($name);
}
}
if (count($opts)) {
$form['sbp_attach']['sbp_attach_field_types'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Fields to index'),
'#default_value' => search_by_page_setting_get('sbp_attach_field_types', $environment, array()),
'#options' => $opts,
'#description' => t('Choose which field types contain attachments you would like to have indexed by Search by Page. Use the Control or Command key to select multiple types or undo your selections.'),
'#weight' => 1,
);
}
else {
$form['sbp_attach']['no_field_info'] = array(
'#type' => 'markup',
'#value' => '<p>' . t('No field types supporting file attachments were found. No attachments will be indexed.') . '</p>',
'#weight' => 1,
);
}
// Other options
$form['sbp_attach']['sbp_options_section_markup'] = array(
'#type' => 'markup',
'#value' => '<p><strong>' . t('Options:') . '</strong></p>',
'#weight' => 2,
);
$form['sbp_attach']['sbp_attach_only_listed'] = array(
'#type' => 'checkbox',
'#title' => t('Limit to displayed files'),
'#default_value' => search_by_page_setting_get('sbp_attach_only_listed', $environment, 0),
'#description' => t('The File field allows you to specify whether a particular attached file should be displayed on the site. If you check this option, Search by Page Attachments will only search for files that have been marked as Displayed. Otherwise, all attached files will be searched.'),
'#weight' => 3,
);
$form['sbp_attach']['sbp_attach_prepend_node_title'] = array(
'#type' => 'checkbox',
'#title' => t('Prepend content item title to file name'),
'#default_value' => search_by_page_setting_get('sbp_attach_prepend_node_title', $environment, 0),
'#description' => t('When an attached file is presented to the user in search results, the results will display a title, which defaults to the file name. If you check this box, the content item title will be prepended to the file name.'),
'#weight' => 4,
);
$form['sbp_attach']['sbp_attach_title_sep'] = array(
'#type' => 'textfield',
'#title' => t('Content item title separator'),
'#default_value' => search_by_page_setting_get('sbp_attach_title_sep', $environment, '/'),
'#description' => t('If you have chosen to prepend the content item title to the file name, this separator will be put between the item title and the file name.'),
'#weight' => 5,
);
$form['sbp_attach']['sbp_attach_use_description'] = array(
'#type' => 'checkbox',
'#title' => t('Substitute description for file name'),
'#default_value' => search_by_page_setting_get('sbp_attach_use_description', $environment, 0),
'#description' => t('When an attached file is presented to the user in search results, the results will display a title, which is the file name by default. If you check this box, and the file has a description defined, the description will be substituted for the file name in the search result title.'),
'#weight' => 6,
);
$form['sbp_attach']['sbp_attach_role'] = array(
'#type' => 'radios',
'#title' => t('Role for indexing'),
'#options' => user_roles(),
'#default_value' => search_by_page_setting_get('sbp_attach_role', $environment, DRUPAL_ANONYMOUS_RID),
'#weight' => 7,
'#description' => t("When Search by Page indexes attached files for searching, the files will be viewed from the perspective and permissions of a user with this role."),
);
$times = array(
'1' => t('1 second'),
'3600' => t('1 hour'),
'86400' => t('1 day'),
'604800' => t('1 week'),
'31449600' => t('1 year'),
'0' => t('Never'),
);
$form['sbp_attach']['sbp_attach_min_time'] = array(
'#type' => 'select',
'#title' => t('Minimum reindexing time'),
'#options' => $times,
'#default_value' => search_by_page_setting_get('sbp_attach_min_time', $environment, 0),
'#weight' => 8,
'#description' => t("Search by Page automatically indexes attachments on new content items, and reindexes attachments if the content item they are attached to is updated. After indexing these updated attachments, Search by Page can also cycle through previously-indexed attachments, in case the file may have been updated without the content item it is attached to being updated. This would be necessary if files on the site are maintained and updated by a separate process (e.g., log files, replacement files added by FTP, etc.). By default, Search by Page will not reindex an attachment until the content item it is attached to is updated, but if you need attachments to be reindexed, you can set the minimum indexing cycle time here. In this case, attachments will be reindexed periodically, along with other Search by Page content, after waiting at least the minimum time set here before reindexing."),
);
$form['sbp_attach']['sbp_attach_max_time'] = array(
'#type' => 'select',
'#title' => t('Maximum reindexing time'),
'#options' => $times,
'#default_value' => search_by_page_setting_get('sbp_attach_max_time', $environment, 0),
'#weight' => 9,
'#description' => t("Conversely to the minimum reindexing time (see above), Search by Page can be set to prioritize reindexing each attachment (by marking it as needing immediate reindexing) after this amount of time has passed. This has higher priority than the cycle-through reindexing of the setting above.") . ' ' . t('But be careful with this setting! If you set it too small, it can interfere with new content being indexed, because the reindexed content will have equal priority to content that has never been indexed. So make sure your settings allow for enough time for new content to be indexed before forcing reindexing.'),
);
// Add a link to helper function config page
$form['sbp_attach']['helpers'] = array(
'#type' => 'markup',
'#value' => '<p>' . l(t('Configure helper functions for extracting text from attachment files'), 'admin/config/search/search_files/helpers') . '</p>',
'#weight' => 10,
);
return $form;
}