1

I'm creating website for a hostel, in this there are two roles (guest and property owner).

if i give 'access callback' => TRUE the page can be accessed by both of the property owner and guest, but i don't need it, the page should be accessed by only property owners.

5
+50

The callback is, well the callback; the function that will be run to determine access for the path.

The arguments are the arguments provided to that function for context. They can be static, or come from parts of the URL (not query params).

What you need to do is instead of TRUE, provide the name of a function which determines whether the current user is a "property owner", and return TRUE or FALSE from that function to allow/deny access respectively.

The common way to achieve that for role-based access is to use hook_permission to provide your own permission to the system, call it "access top secret area" or whatever, grant the new permission to the property owner role through the UI, and change the access arguments to an array containing that new role.

The default access callback is user_access, so it will have the effect of running

$access = user_access('access top secret data');

Obviously if you need more advanced logic, e.g. to determine that a property owner is accessing only data on a property they actually own, a custom callback will make more sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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