Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I have 30 Content Types on the site I am building at the moment. So editing the Search Restriction via each content type page takes about 15min. So I have written some code to put it all on one page - a tab that is added to the Search Settings page at 'admin/settings/search/restrict'.
This code can be added to your module without any changes to your code.
/**
* Implementation of hook_menu().
*/
function search_block_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/search/main',
'title' => t('Main'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items[] = array(
'path' => 'admin/settings/search/restrict',
'title' => t('Restrict Search'),
'description' => t('Restrict the node types that are searched.'),
'callback' => 'search_block_restrict_page',
'type' => MENU_LOCAL_TASK,
'access' => user_access('restrict searches'),
);
}
return $items;
}
/**
*
*/
function search_block_restrict_page(){
$output = "Restrict Search Results by Node type.<br />";
$output .= drupal_get_form('search_block_restrict_form');
return $output;
}
/**
*
*/
function search_block_restrict_form($form_state){
$types = node_get_types($op = 'types', $node);
//print_r($types);
foreach($types as $key => $array){
$enabled = variable_get('search_block_' . $key, FALSE);
if ($enabled){
$icon = theme('image', 'misc/watchdog-error.png', t('error'), t('error'));
}
else{
$icon = theme('image', 'misc/watchdog-ok.png', t('ok'), t('ok'));
}
$form[$key] = array(
'#type' => 'radios',
'#title' => $icon .' '. $array->name ,
'#default_value' => $enabled,
'#options' => array(
FALSE => t('Allow Searches'),
TRUE => t('Restrict Searches'),
),
);
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}
/**
*
*/
function search_block_restrict_form_submit($form, $form_values) {
foreach($form_values as $key => $data){
switch ($key) {
case 'op':
case 'submit':
case 'form_token':
case 'form_id':
break;
default:
variable_set('search_block_' . $key, $data);
}
}
drupal_set_message(t('Your form has been saved.'));
}
Regards
Geoff
Comment | File | Size | Author |
---|---|---|---|
#2 | editing_page.patch | 2.28 KB | behindthepage |
Comments
Comment #1
deviantintegral CreditAttribution: deviantintegral commentedThanks for the code. I have a few thoughts:
<p>
instead of using<br />
.--Andrew
Comment #2
behindthepage CreditAttribution: behindthepage commentedPatch attached with changes you suggested.
Regards
Geoff
Comment #3
deviantintegral CreditAttribution: deviantintegral commentedI've committed this patch in #112460: Add disclosure in html above links... I had to manually add the file information at the top - please be sure to include that in future patches.
Thanks!
--Andrew
Comment #4
deviantintegral CreditAttribution: deviantintegral commentedComment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.