7

I'm using Drupal 7 to create a project linking organizations to volunteers. My initial approach is to use profile module to create different profiles for each role (volunteer & organization). Is it possible to create new fields which would attach only to a selected role?

3

This is a great example use-case for the Profile 2 module.

As listed on the project page:

Profile2 allows for creating multiple profile types, which may be assigned to roles via permissions (e.g. a general profile + a customer profile)

  • Unfortunately, this isn't quite the use case I'm after. I don't want to add additional profiles to users by role, I want to extend roles to have more fields. For instance: a profile type: Volunteer, and a profile type: Organization, each with their distinct fields. Profile2 seems to handle this rather awkwardly... – starsinmypockets May 20 '11 at 18:51
  • @starsinmypockets In Drupal 7, fields are added to nodes, comments, taxonomy terms, and users. There isn't a way to add a field to roles, which are not considered entities. The closer you can get is what reported by @tim.plunkett, which is to have a different profile type for each user having specific roles. – kiamlaluno May 20 '11 at 23:58
  • 2
    From an OO perspective, I'm basically trying to extend the user entity, although coding entirely new entities to use as roles seems like a lot of work ;) – starsinmypockets May 21 '11 at 22:01
3

I guess you could also try to add all fields to the user directly and then use a custom hook_field_access() implementation to control when they are shown for edit/view.

0

I think you can use https://drupal.org/project/user_role_field This module allows you to specify role specific fields. When creating a new field, you specify for what roles this field is enabled..

-1

Sounds like a good idea to collect all fields in one entity. You could then have a enumerator-field, where you could choose entity-sub-type (organization or volunteer). That would be needed in case the author had authority to create both. You can use User Role Field to hide the fields that the author is not allowed to see. You can use Field Permissions to restrict access that the author and viewer is not allowed to access. You can use also hide or show fields dependent on values of other fields with Conditional Fields. The dependee field would then be the enumerator-field. You could probably use Computed Field to add extra logic dependent on sub-type.

I like to use taxonomy for enumerator, but it could be a text list instead.

You would probably also like to group the subtype specific fields together in a drupal.org/project/field_group

This pattern could just as well be applied on contenttypes. I think I will try it out.

In Microsoft Sharepoint, ContentTypes has had inheritance for years. I wonder if it will come in a future Drupal version.

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.