1

I have a person node. There are some internal fields only the admin can change (e.g. Internal person code). Some other fields users with certain roles can change (e.g. first name...).

I have built a custom page using panels for this; I added the desired fields for normal users to the panel and Then I added a selection rule to the variant, enabling the variant for the normal users.

When a normal user opens the form and saves it, the internal fields, which only should be edited by the admin are set to NULL, because they were not submitted of course.

Is there any setting I missed? I don't want to add all the internal fields.

Thanks.

4
  • possible duplicate of Field level permissions in Drupal 7
    – Anil Sagar
    Apr 30 '14 at 10:33
  • Thanks for that. This is a good solution, but not exactly what I want. With this module I have to put ALL the fields on the panel. But I only want the fields, that I want :-)
    – schulle877
    Apr 30 '14 at 10:49
  • I tested the "Field permissions" module. It looks great, but as I said before, I have to put all fields of the node on the panel, not only the desired ones.
    – schulle877
    Apr 30 '14 at 11:00
  • You could create a separate page for the Admin to access and edit the information, then only display the viewable fields to the user.
    – Geoff
    Apr 30 '14 at 14:04
1

After some research I found out, that it is very important to have the full node form be added to the panel to get all fields (like publishing option, date created...), so the submit routine gets data for all node fields.

You can show/hide fields for certain roles using the Field Level Permission Module for the standard Drupal roles. But I like to use the OG roles to define the permissions. There is already an OG function for this under admin/config/group/permissions.

I did it this way:

  1. Activate the node/%/edit page under pages
  2. Create a variant for editing node of a certain type
  3. Add all required fields, which should be shown to the normal user to the form and layout it
  4. Add the submit buttons to the form
  5. Add General Form to the panel, so that all fields, which are not build before are added to the form (like publishing status, author, date created...)
  6. Goto admin/config/group/permissions and set the edit rights for the fields, the normal user should not see. The fields then are not on the node form anymore, but the values remain in the database.

I hope that helps someone else.

0

If it's a custom form, use the #access property to set the values.

$form['some_field'] = array
(
  '#type' => 'textfield',
  '#title'=> t('Enter a value'),
  '#default_value' => $node->some_field,
  '#access' => user_access('edit_some_field'),
);

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.