Hello everybody,
I am still a newbie and hope you can turn a blind eye to my questions:
1.) My module provides a small registration form for my website
visitors (name, username, email, ...) in the frontend. But I want
to use the same module for the backend to be used by registered
users.
2.) I need a function for logged in users that is part of the .module-file
I wrote: a list of all users (in the users-table of the drupal database).
But how is it possible to make such a function available in the same module?
3.) Assuming I have implemeted this function: how can I grant user
access only for authenticated users to this particular function?
I really stuck on this question.
If anybody could help me here I would appreciate a lot!
Thanks,
Soezkan
Comments
1.) My module provides a
I'm not getting what's going on here. Why do "registered" users need to register? Also, there is no frontend/backend with drupal (unlike joomla). Maybe some more info would help me understand what you're asking.
A module is just some code, it doesn't really have a concept of what belongs and what doesn't. I always create a single custom module for each new site and place all custom code in it, whether related or not, and just comment the functions appropriately. If you need to add function to your module, just add it-- the module doesn't know the difference.
You can create a permission for your module/function with an access callback and just check the permission for authenticated users on the admin/user/access page.
You can also check for logged in users with code like:
Also, there's the http://drupal.org/project/user_list module and a few php snippets on the snippets pages (like http://drupal.org/node/82002) you can look at for some ways of handling user lists.
===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz
Ideas
1. What about the contact module included in the core?
2. You could move the function into an include file and include it in both modules using:
require_once './'. drupal_get_path('module', 'module_name') .'/includes/functions.php';
3. You can specify the user access at the menu level using the 'access' => user_access('something') in the menu hook. Or I suppose you could do a check in the function, using the $user object and check that $user->uid is set (for any logged in user) or the $user->roles array.
But, I'm also new so maybe one of the Drupal experts will have other suggestions.
Thank you so much for the
Thank you so much for the replies.
Yes I still think in Joomla terms.
So the check with $user->uid is a very helpful hint and lapses the other
issues. Because now I can switch within my Output-function and show
the specific content to the according user.
Cheers,
Soezkan