With the following code, I'm getting warning: Invalid argument supplied for foreach(). This is obviously a syntax error on my part, but I'm not getting it.
In the implemented hook_insert function, I have the following code. (->images is supposed to be an array of image nodes loaded earlier in the code.)
On my web site I want to have additional profile fields based on the users role. Some roles need certain profile fields, while others do not. And further it would be BAD to let all roles have all the profile fields.
...so...
I took a look at the profile.module and have a proposal which I want to swing by y'all before I implement it.
Database new table:
profile_roles: "fid" matching profile.fid, "role_id" matching the role id -- affording a flexible mapping between role and profile fields ... TBD: Need a way to declare the profile field is suitable for all roles
Alternatively ... instead of making a new table, the profile table could have a new column "roles" in which you enter the roles as a space-separated item. Then to check whether that profile field is suitable for the given role you simply do a LIKE query.
The visible changes would be in the admin area where profile fields are defined. Profile field add/edit pages would list the roles, letting the admin define which roles the profile fields are appropriate for.
Then there's several places to change non-visible behavior ... because there's several places where a list of profile fields are made for either display or edit. Those places need changes to ensure that fields are not displayed when the user doesn't have the right role for the given field. The main one of concern is the edit page for the users profile, to make sure that edit widgets are not made for profile/roles they do not have.
Is there a function to determine if a node exists? I could use node_load, but I'm not sure what it returns if a node has been deleted, and I don't actually need to load the node in this case, only to make sure it hasn't been deleted.
As a side note, is there a way to easily determine another node's type without loading it?