This repository has been archived by the owner on Aug 18, 2024. It is now read-only.
Cannot save group reference field programmatically #137
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Copied from https://www.drupal.org/node/2766637
OG's entity reference handler class, OgBehaviorHandler, checks field access before it saves the group memberships, and skips saving if the currently logged in user does not have permission to edit the group reference field. As a result, if the current user does not have permission to edit the group reference field, the field is going to be ignored when the entity is saved programmatically. This can cause problems in two situations:
When content is saved programmatically, (e.g. using node_save()), the values that get saved into the database should not depend on what user is logged in. Actually, I think the entity reference handler class should not be concerned with user access when saving the group memberships. This is low level functionality, and when we get to the point where the entity needs to be saved, the field values should already have been validated.
This PR removes the access check from the membership saving logic. Please let me know if I have taken the right direction with this.