Hi! I'm doing some modifications to the Calendar module theme. I need to have an edit and remove button in the "month-view" for each node but only want to display these buttons to users with sufficient permission to edit or delete these nodes. Is there any way to evaluate a drupal path, say /node/123/edit or node/123/delete for the current user. Like user_access but with drupal paths instead? This would really help me alot. Thanks!

Comments

nevets’s picture

What I think you want is to use node_access, something like this should help

$nid = // Comes from some where :)
$node = node_load($nid);
if ( node_access('update', $node) ) {
  // Can update/edit the node
}
else if ( node_access('delete', $node) ) {
  // Can delete the node
}
gnucifer’s picture

Thank you! Thank you! Thank you! That was exactly what I was looking for! :)

kobnim’s picture

For the more general problem of checking whether user has access to a particular path, I think this might work:

$item = menu_get_item($path);
return ($item && $item['access']) 
patrickd’s picture

And this was exactly what I needed, thank you too!! :-)

niklp’s picture

These days, you probably want to use drupal_valid_path() ?

Beware though, there are open bugs for this function in Drupal 6/7/8 at this time. It will definitely return warnings under certain conditions, and usage of dynamic paths is sketchy here.

technikh’s picture

drupal_valid_path Checks a path exists and the current user has access to it.
https://api.drupal.org/api/drupal/includes!path.inc/function/drupal_vali...

Cheers,
TechNikh

In 30 seconds set up Automated Visual testing of your website. Zero coding. https://drupal.org/project/drulenium
Ever dreamed of styling your view, We have a solution for you. https://drupal.org/project/views_stylizer

elijah lynn’s picture

-----------------------------------------------
The Future is Open!

seant’s picture

Thank you