For now if user have view permission but haven't edit permission, field in edit form will be hidden. Is possible to not hide but show greyed out field (#readonly => TRUE)?

Users would be sure that they filled field correctly and now they can't update it.

Comments

rbennata’s picture

I need this functionality too.

allio_froggio’s picture

The current implementation is confusing, as you can't actually edit the setting but it appears that you can (still see the drop down, but it doesn't save). Showing just a greyed out box would be awesome!

joachim’s picture

+1 for this.

Though AFAIK making a form element read-only is a bit flaky in FormAPI -- setting #disabled = TRUE can be worked around with Javascript, so the module would have to make sure that a changed value is not accepted.

honza pobořil’s picture

Sorry, my mistake. Correct attribute is #disabled

joachim’s picture

> Though AFAIK making a form element read-only is a bit flaky in FormAPI -- setting #disabled = TRUE can be worked around with Javascript, so the module would have to make sure that a changed value is not accepted.

Turns out I'm wrong about this :)

fraweg’s picture

+1
I need this feature too..

Have someone sove this issue with a workaround?

Best regards
Frank

fraweg’s picture

I hope this thread is not dead ;-) I really want this feature...

Best regards
Frank

Edit:

When I read this:
#######################
Maintainers for Field Permissions

Rob Loach - 21 commits
last: 23 weeks ago, first: 1 year ago

markus_petrux - 28 commits
last: 2 years ago, first: 2 years ago
#######################

I thing there is no activity in this project... :-(

jelo’s picture

I need the same feature as well. Users should be able to view the value for specific fields on the user edit form (e.g. with a greyed out field), even though they might not have the permission to edit the value.

sw3b’s picture

+1 on this feature ! Anyone find a workaround for this request ?!?

fraweg’s picture

I need a work arround too :-( !

fraweg’s picture

Maybe its a good idea to let the user choose in witch way he want to use it. Maybe someone want to have it hide and someone like it greyed out.

Best regards
Frank

jelo’s picture

That would be ideal, e.g. a configuration option in the settings to decide if read-only fields should not be shown on the edit form or be shown as greyed out. In such a configuration screen, it would be great if we could enter text as a description/notification to the user as well why the field is greyed out. In my use case, we would have to specify that the data is coming from another system and that the user has to change it there to update the value... I would be fine with a global setting for all fields, but maybe other users would need a more granular approach, e.g. configuration of visibility and notification per field.

jelo’s picture

Has anyone found a solution for this?

fraweg’s picture

Hello,

no, not really.. :-(

Best regards
Frank

mordonez’s picture

Version: 7.x-1.0-beta2 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new2.21 KB

Hi,

I did a solution for this problem, basically I created a new permission "Edit (read-only) anyone's value". If one role has this permission, the user with this role can edit but can't change the value of the field.

I used the hook hook_field_widget_form_alter for access the field's attributes and change the disabled widget's attribute if user has this new permission and not the permission "Edit anyone's value".

This hook was introduced in Drupal 7.8 but I hope this helps.

mordonez’s picture

I improved the solution using field_permissions_field_attach_form instead hook_field_widget_form_alter

Status: Needs review » Needs work

The last submitted patch, field_permissions_edit_field_read_only_1547172_16.patch, failed testing.

mordonez’s picture

Status: Needs work » Needs review
StatusFileSize
new2.63 KB
fraweg’s picture

Hello,

Maybe its a good idea to let the user choose in witch way he want to use it. Maybe someone want to have it hide and someone like it greyed out.

Did the patch #18 respect this?

Best regards
Frank

mordonez’s picture

Yes

fraweg’s picture

StatusFileSize
new31.97 KB

Hello,

at first..many thanks for your work in this issue!

For me the test with patch #18 failed. I have no error messages but when I activate the new field I can edit and in this case change the value of this field. Nothing is greyed out. In the screenshot you can see my setting...
Do I something wrong?

Best regards
Frank

mordonez’s picture

StatusFileSize
new35.86 KB
new80.02 KB

Hi fraweg,

thanks for your feedback. I tried with a fresh install and it works. Did you tried to rebuild permissions at admin/reports/status/rebuild?

fraweg’s picture

Hello,

Did you tried to rebuild permissions at admin/reports/status/rebuild?

Thanks for that tip...! Now it works ! Thanks so much for your support.

Is there a way to make it also work with fields wich have a selectbox? For example the Birthday module. I think no one should be able to change his birthday ;-)

Best regards
Frank

mordonez’s picture

It works with core fields, entity reference, date... all fields that correctly implements field API. But It seems the Birthday module not the case.

Sorry.

attiks’s picture

Status: Needs review » Reviewed & tested by the community

It works perfectly

JThan’s picture

As writing this, the solution popped up: Clear the cache also. That Drupal cache is just too good. So, yeahh, works, pleas include in the module.


____________________________________________
I tried the today. the read-only option is showing, but I can still edit the field. It is a new installation with some other Modules already installed. The field can be hidden, but greying it out with your patch did not work.

I did rebuild the permisions.

___________________________________________

dsrikanth’s picture

This is great! Thank you so much for the patch!

I tested it out and it works great. However it isn't working as expected with Field Collections. The fields inside the field collection shows up in the editable format. I am guessing its because filed collection doesn't store it as $form_state['field'][$field_name]

I encountered this problem in office hours module and wrote a patch
http://drupal.org/node/1689296#comment-6925544
http://drupal.org/node/1689296#comment-6956622

Similar approach might help fix this for fields inside Field Collections

kaizerking’s picture

@dsrikanth could you please provide patch supporting field collection i am looking for this

dsrikanth’s picture

@kaizerking - sorry, I did give it a shot but couldn't get it to work. I will post an update if I find a way to get this done. For now, I am fixing my issue by hardcoding my field collection fields name and disabling them inside this module.

elvis2’s picture

@mordonez Thanks for the patch. I was able to successfully patch my version of field_permissions 7.x-1.x-dev (from 2012-01-11) with #18.

I have a question about the language. Instead of using "edit (read-only)" as the label would "view (read only)" make more sense? After patching then editing a field I was a little confused by the word "edit". Maybe you can shed some light on that.

Thanks!

rexington’s picture

mordonez, thank you for that patch! #18 worked perfectly for me.

mpark’s picture

This patch doesnt working, I dont know, but is this line correct?

function field_permissions_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
global $user;
list($id,,$bundle) = entity_extract_ids($entity_type, $entity);
katannshaw’s picture

@dsrikanth: Has there been any update on creating a patch to get this to work with field collection? As with you and kaizerking, this patch works great for me on regular fields but not on field collection fields, as they're still editable. Also, could you post your code for hardcoding field collection fields into read only fields? I'm new to PHP, so that would be a great temporary fix. Thanks.

By George I believe I've (partially) got it. What didn't work was to go into the field collections properties at http://mysite/admin/structure/field-collections and attempt to customize the permissions there.

What did work was for me to go to the *main field settings page for my content type* at admin/structure/types/manage/[content-type-name]/fields/[field-name], changing the Field visibility and permissions to Custom permissions, and selecting the "read only" option from there. Once I did that, it worked for the field collection fields as well.

I still cannot get it to accept one field as read-only within a field collection though. Hopefully a new patch/solution comes out for that.

Hope it helps. Great patch!

agerson’s picture

+1 for this functionality. Can we get it added to the dev branch?

dema501’s picture

#18 works for me

rterman’s picture

I tried on my own site as well as a blank site and it didn't work. But when I removed the following lines in the patch in #18, it worked. Why does the entity have to be new?

  if(empty($id)) {
    return ;
  }
  // Prevent AJAX calls.
  if (!empty($form_state['triggering_element']['#ajax'])) {
    return;
  }
liliplanet’s picture

Thank you for this module! The problem I'm having is that when I select 'Authenticated' as want only Premium and Platinum to be able to add and edit, the whole row gets selected and unable to deselect Premium and Platinum. Any guidance would be most appreciated :)

anrikun’s picture

You may try the Field Readonly module.

duckydan’s picture

Leo Jiménez’s picture

Issue summary: View changes

Not working for me patch on #18. I clear cache and rebuild permissions. Module Field Readonly on #38 work correctly.

Thanks

gocaps’s picture

I had problems with patch #18. I solved the issue by implementing hook_form_alter in my template.php file:


/* 
 * Override node edit forms to make specific fields "read only"
 */
function mytheme_form_alter(&$form, &$form_state, $form_id) {
  
  /*
   * Optional: Allow a specific role to edit the otherwise "read only" fields
   * All other roles cannot edit the fields defined below
   */
  global $user;
  if(in_array('Custom Role Name', $user->roles)) return;

  $fields = null;

  /*
   * Specify cases for each individual content type node form
   * Ie. If content type name is "news", create case for news_node_form, etc.
   */
  switch($form_id) {

    case 'news_node_form':
	  $fields = array('title', 'field_news_date', 'field_news_author');
      break;

    case 'event_node_form':
	  $fields = array('field_event_start_date', 'field_event_location');
      break;
      
    // continue to add other cases as needed  
  }
  
  if($fields) {
    foreach($fields as $field) {
      $form[$field]['#disabled'] = TRUE;
    }
  }
}

And then added some CSS to highlight the disabled fields:

/* Apply styles in your theme to give disabled fields the "greyed out" look */
.form-disabled input.form-autocomplete, 
.form-disabled input.form-text, 
.form-disabled input.form-file, 
.form-disabled textarea.form-textarea, 
.form-disabled select.form-select {
	background-color: #eee;
	color: #777;
}
romansta’s picture

I had also problems with patch #18 and tried the readonly-module too - without success. #41 did it for me.

liquidcms’s picture

tried patch in #18 - seems to work as expected. seems like an obvious addition to this module; would be good if we could get it committed.

loparr’s picture

@liquidcms what version did you use for patching? dev or 7.x-1.0-beta2

thank you

liquidcms’s picture

7.x-1.0-beta2

marcus_clements’s picture

Thanks for fixing this.
The patch works well in 7.x-1.0-beta2 and is a requirement for my project so I'd like to see this committed.

mariacha1’s picture

Status: Reviewed & tested by the community » Postponed
Parent issue: » #1448154: Allow other modules to extend this module via alterers and hooks

I'd prefer to do this with a hook once https://www.drupal.org/node/1448154 is committed.

zekvyrin’s picture

Status: Postponed » Needs work

I see the related patch is committed.. so I'm updating the issue to needs work, for someone to implement it with the hook probably

roflcopterDorrie’s picture

Whilst waiting for some good citizen to implement with the hook, I have updated so it applies to dev

thulenb’s picture

Is it possible to committ this soon?

nwom’s picture

#49 worked great. Thank you! Any chance this can get committed?

nwom’s picture

Actually just ran into a small issue. When setting up Field Permissions to hide an entity reference field (for specific roles) that has add/edit buttons via Entity Connect, it works great. Both the field and the buttons are hidden.

However, when using this patch and making the field instead Read Only, the field shows up as read only (which is great), but it allows you to still use the add/edit buttons (not intended). I'm guessing this problem can occur with other modules as well.

w01f’s picture

Is there a D8 version of this patch/feature? I think a toggle/selector to hide/read-only would be great, as I have several fields I'd like to remain hidden, but a few that would be best for read-only/greyed-out.

mrpauldriver’s picture

I too would like to see similar functionality for the D8 version and have opened separate feature request.

Provide a form display formatter for greying-out a field or hiding it completely

bluegeek9’s picture

Status: Needs work » Closed (outdated)

Field Permissions does not support Drupal 7.