I have a node (group) with an entity reference field that is used to link it to other nodes (stations). The relationship between them is 1:N (one group : many stations).

The problem is that I need to limit the edit widget so that certain users can see (and also edit) only specific station links. I have no problems with limiting which stations can be added, I know that I can easily do that via custom validation + entityreference selection widget.

The real trouble is with limiting which already existing references to stations can be deleted / viewed. Imagine that I have this structure:


//User1 is allowed to see (and edit) only station1, user2 only station2.

Then I'd need to edit the Group1 edit form in a way that when user1 access it he/she only sees the station1 in the stations references widget (and can therefore remove only that referece). Following the same principle, when user2 access the group1 edit form, he/she can only see (and edit) the station2 reference.

I know how to limit the deletion itself via setting the '#disable' property of the individual reference...

$form['entity_reference_field_name']['und'][1]['target_id']['#disabled'] = true;

...but that doesn't hide, just disables it for removal.

There's also the possibility of setting the '#access' property of it which actually hides the record, the problem is that it looks just terribly ugly (and like a clear 'hack').

$form['entity_reference_field_name']['und'][1]['target_id']['#access'] = false;

Looks ugly

I can't unset the reference because it would delete it.

So, does anyone have any idea how to it? Preferably without having to clone the entity reference module and editing its core.

  • Do you have anything in place so that users in Group 1 have "some" role which the users from Group 2 do not have. And similarly a 2nd role for Group 2, which Group 1 users do not have? If you don't have such a roles related separation, can you think of one to have a role for each group? In that case there is, I think, a straight forward solution ... – Pierre.Vriens Jul 14 '15 at 12:00
  • Unfortunately no, the access is determined dynamically based on a few things including but not being limited to permission. – Petrroll Jul 14 '15 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.