I'm using this in a D7 project that I've just starting, so here is the ported version that I done this evening.

I needed the "exclude all" from the search, so I also implemented this feature. #602338: Pls, make it possible to disallow *ALL* roles to search content per (!) content type

The logic behind parsing the roles has been reduced to an array_filter / array_intercept_keys and this reduced the amount of code required.

There has been some minor reformatting, strict PHP warning errors resolved and removed access to the advanced form type element when there is 0 or 1 types avaliable. It didn't make any sense to me to show a single checkbox in a filter form!

Feel free to use or ignore.

Comments

alan d.’s picture

StatusFileSize
new3.2 KB
new10.99 KB

I've included the patch against 6--1 Branch (You must be working via a tagged version as the branch was not up to date) and a zip since there were significant changes.

johnpitcairn’s picture

Subscribe. We're considering specifying Drupal 7 for a site that has a fairly long deadline, I'm assessing the D7 status of modules we might need.

mrfelton’s picture

subs. Can we get whats here into a new CVS branch?

davemurphy’s picture

subscribe

tomcatuk’s picture

subbing

danny_joris’s picture

subscribing

Niklas Fiekas’s picture

Subscribe.

Niklas Fiekas’s picture

Awsome patch, thank you.
Just a small fix.

Leeteq’s picture

Title: Drupal 7 port and "Exclude all" feature » D7 port and "Exclude all" feature for Search Restrict
Version: 6.x-1.3 » 6.x-1.x-dev
Category: feature » task

How about a D7 branch?

jeffschuler’s picture

StatusFileSize
new9.74 KB

Rerolled #1 against search_restrict HEAD (from git,) applied change from #8, and corrected all suggestions from Coder module (on "minor" setting.)

Is this module still being maintained?

robert castelo’s picture

Thanks, I'll review again at the weekend.

Niklas Fiekas’s picture

jeffschuler's patch in #10 looks good, applied and works. Did you have time to review it, yet?

mraichelson’s picture

subscribe

sijuwi’s picture

On our site: www.freedomfromtorture.org if you type in certain phrases, eg "Body of Evidence" the page crashes for anonymous users:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ESCAPE '\\') AND .................

alan d.’s picture

To assist, actually include the mysql dump otherwise to could be difficult to replicate.

gagarine’s picture

Thanks for the patch in #10. Some point I found:

#search_restrict_content_type_form is useless we can do the job directly in search_restrict_form_node_type_form_alter
Take a look at comment_form_node_type_form_alter function (core comment module).

#add the settings in vertical tab
In function search_restrict_content_type_form(&$form) add the form element in $form['additional_settings']['search_restrict']. With that you also don't need the ugly array_unshift. EDIT no this one is for adding the additional submit function.

# Exclude all roles should not be under the "role" subtitle because is not a role. "$roles = array('-1' => $msg) + $roles;" is also hard to read.

+++ b/search_restrict.moduleundefined
@@ -19,101 +28,76 @@ function search_restrict_form_node_type_form_alter(&$form, &$form_state) {
+  natcasesort($roles);
+  $msg = t('Exclude all roles from search');
+  $roles = array('-1' => $msg) + $roles;

# Long description. "All roles can search unless "%msg" is selected" is enough.

+++ b/search_restrict.moduleundefined
@@ -19,101 +28,76 @@ function search_restrict_form_node_type_form_alter(&$form, &$form_state) {
+    '#description' => t('Select which user roles can search for this content type. By default all roles can search unless "%msg" is selected, which overrides all other role restrictions.', array('%msg' => $msg)),
alan d.’s picture

Status: Needs review » Needs work

PS: I've ported / merged features onto search_config project. The core restrictions on search are permission based, and the UI settings are under the main search config page.

jeffschuler’s picture

Here's Alan D.s' commit to search_config, which started with #1197560: Refactored Drupal 7 port (in the search_config project queue.)

alan d.’s picture

Hi jeff, use the project page, the first release of mine was 7.x-1.0-beta1

WGViana’s picture

subscribing

robert castelo’s picture

Status: Needs work » Fixed

D7 version released - thanks for your contributions.

alan d.’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Priority: Normal » Major
Status: Fixed » Active

For context, I'm recycling this issue.

I'm using the same code in search_config, and hit a nasty bug in the count query (a core Drupal issue), so you may want to investigate / modify this. Here is the change that I had to do there:

    // A core bug results in a DB error if we use the following: Ref: #1210072
    // $query->condition($node . '.type', array($excluded_content_types), 'NOT IN');
    if (!empty($excluded_content_types)) {
      $db_and = db_and();
      foreach ($excluded_content_types as $type) {
        $db_and->condition($node . '.type', $type, '!=');
      }
      $query->condition($db_and);
    }

The resulting SQL is the same, the change was from not using type NOT IN(type a, type b) to type != type a AND type != type b

alan d.’s picture

Component: Code » Documentation
Priority: Major » Normal

The core bug has been fixed in Drupal 7.8, maybe a message on the project page about this requirement to finish this issue off!

For reference:

#1112854: Subqueries use wrong arguments
#1202416: Search is not working with node access turned on