Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Cannot save group reference field programmatically #137

Closed
wants to merge 4 commits into from

Conversation

glekli
Copy link
Contributor

@glekli glekli commented Jul 16, 2016

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:

  • The current user is irrelevant to the content being updated. E.g. during drush run
  • The user may not have access to directly edit the group reference field, but custom code may want to be able to change the group memberships based on some other action taken by the user.

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.

pfrenssen pushed a commit to pfrenssen/og that referenced this pull request Aug 9, 2016
…ndles

Fix the description for the group type checkbox when creating a new bundle
@MPParsley MPParsley linked an issue Aug 15, 2020 that may be closed by this pull request
@claudiu-cristea
Copy link
Collaborator

Since https://www.drupal.org/project/og/issues/3467694 was merged into the 8.x-1.x branch, the development has been moved to https://www.drupal.org/project/og. If this change is still actual, please open an issue at https://www.drupal.org/project/issues/og and provide there a merge request similar with this pull request.

Thank you for contributing to Organic groups module.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot save group reference field programmatically
3 participants