0

I have an entity with many field (about 200) collecting information about buildings (area, height, conditioning system, ...)
my client has asked me to show specific fields in groups for editing, where user can choose from menu "group 1" and see only those fields
it is also possible that users will only visit some groups they want, and leave some of groups un-edited for later
how do i show specific fields of one entity, according to path? /node/1/edit/g1 for fields 1 to 20, node/1/edit/g2 for fields 21 to 30 and ....

extra info: i'ts not about permissions at all, the same user, will fill group 1 today, will comeback tomorrow and fill group2 if wanted to
field collections looks promising, can it do that? instead of deciding by user permission, deciding by path?

1 Answer 1

0

One way to do it is by using field gropups and custom permissions. Start by installing field groups module to make it possible to group your fields at all. Move your fields into different control groups and use for example tab groups and tab items in a way to make the editing page pleasing.

If you want detailed asccess rights for different user groups, add some code to do this.

Add your own permissions by using hook_permissions() For example

function my_module_permissions() {
  return array(
     'edit group1' => array(
      'title' => t('Edit group1 section'),
      'description' => t('Edit field group group1 in Building.'),
     ),
   );
}

In a hook_form_alter() function, you can hide/show field groups like this:

// Check if the current user has rights to see this group and its fields
if(!user_access('edit group1', $user)) {
 // Loop through all group fields and hide them
 foreach($form['#groups']['group1']->children as $index => $groupField){
   $form[$groupField]['#access'] = FALSE;
 }
}

You don't have to hide the group itself, hideing all it's fields will render it invisible.

Then it's just a matter of settings the right permissions to the right user groups.

Pros:

  • Detailed permissions just for the things you need
  • Field groups are pleasing to use :-)

Cons: You need to do some coding

Second way

An other way is to use field collections module where a collection itself will be treated as fields in a sense. I guess by adding field permissions you will be able to control each fild collection's permissions.

Pros: no coding :-)

Cons:

  • By adding field collection you adding a new layer of abstraction wich might complicate things for you later on.
  • field collections isn't supported by all modules you might use - check it before starting this path.
  • It will get a bit messy in the permissions hanlding page

Your Answer

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

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