2

I'm using Drupal 7 with Webform and Content Access contrib modules.

I wrote a little snippet that displays all items for a given menu, and greys out the ones that the user doesn't have access to, while the accessible ones are links.

I get the access control information with

menu_link_load(menu_load_links(menu_my_menu)[mlid])[access]

...if that helps at all. It returns 1 if access should be granted, and NULL if not.

The problem I'm encountering is that, while this code works swimmingly for normal nodes, webforms seem to return a 1 for access even when the logged-in user does not have permission to submit that form. So the link shows up, and then it takes the user to a page that says "You do not have permission to view this form."

What function do I call to find out whether a webform of a certain path (or title or whatever I can find out from menu_link_load) should be visible to the user?

1

1 Answer 1

2

I think the easiest way to resolve this is to use Content Access and specify the View permission for a Webform, rather than Webform's "can submit" permission. In other words, by using the Content Access module's View Permission instead of the Webform "can submit" permission, you can utilize the code you're currently using. To do this you'll have to set a separate View permission for each Webform.

The problem originates from Webform's permissions conflict with Drupal core: Drupal's standard View permission may be true, but the Webform "You can submit this form" permission can be false, which gives a different Access Denied message from above.

I attempted to dig up an alternate solution, creating some custom code to derive the access for Webform menu items, but it really was looking horrendous. Webform does not have a function that returns "You can submit this webform" access, and trying to efficiently determine if a menu item is a webform was looking pretty foul.

1
  • Works brilliantly. I hadn't realized that I hadn't enabled per-node access control on webforms, and that I was only using the built-in "can submit" permissions. You've saved whatever hair I haven't already pulled out in frustration.
    – beth
    May 11, 2012 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.