views:

46

answers:

2

What block visibility PHP snippet would show a block only on node pages that the loged-in user can edit? The user may not own the node. In my case, I want to show the Content Complete block to people who can actually populate missing fields.

+3  A: 

check for node_access("update", $node) (more on http://api.drupal.org/api/function/node_access/6)

  //first check whether it is a node page
  if(arg(0) == 'node' && is_numeric(arg(1))){
    //load $node object
    $node = node_load(arg(1))
    //check for node update access
    if (node_access("update", $node)){
      return TRUE;
    }
  }

barraponto
+1 - a straight solution. I'd replace the if clause with a `return node_access("update", $node)`, though ;)
Henrik Opel
you're right, although my code is slightly more legible. but if the user knows php, yours is the best suggestion.
barraponto
just do it.btw, remove those off topic comments and, if needed, create another question.
barraponto
A: 

Following is barraponto's solution rewritten for noobs like me and to support multiple conditions.

<?php
$match = FALSE;

// Show block only if user has edit privilges for the node page
// first check whether it is a node page
if(arg(0) == 'node' && is_numeric(arg(1))){
    //load $node object
    $node = node_load(arg(1));
    //check for node update access
    if (node_access("update", $node)){
        $match = TRUE;
    }
}

return $match;
?>
wgrunberg

related questions