03 328 8646

Blog

Hide nodes without access permissions from manage content in Drupal 7

Once you have removed a site editors permission to edit & delete a page it will still show on the admin/content page of the site, and that can be useful for users to see the site structure.

Other times it can be confusing, and often causes at least a momentary thought glitch for the user before they go on to edit whatever it is they logged in for.

You can remove the node from the content listing page altogether if the current user doesn't have permission to perform any operations on it.

Just drop the following into your module and you're good to go.

function MYMODULENAME_form_node_admin_content_alter(&$form, &$form_state, $form_id) {
  //Do we have permission to edit this type of node? remove from
  //content admin page if not.
  foreach ($form['admin']['nodes']['#options'] as $key => $el) {
    //If there are no operations we can perform on this page then don't show it on the list
    if (count($el['operations']) < 1) {
      unset($form['admin']['nodes']['#options'][$key]);
    }
  }
}