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 .'&nbsp;'. $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

CommentFileSizeAuthor
#2 editing_page.patch2.28 KBbehindthepage
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

deviantintegral’s picture

Thanks for the code. I have a few thoughts:

  • search_block_restrict_page() is not going to return valid XHTML output. The text should be in a block element such as <p> instead of using <br />.
  • The confirmation message should be more descriptive ("Your restricted search settings have been saved.")
  • Please generate a patch because some of the indentation is messed up in your paste above.

--Andrew

behindthepage’s picture

FileSize
2.28 KB

Patch attached with changes you suggested.

Regards
Geoff

deviantintegral’s picture

I'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

deviantintegral’s picture

Status: Needs review » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.