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

OgMembership::save() does not update entity audience field #42

Open
schultetwin opened this issue Apr 1, 2015 · 1 comment
Open

OgMembership::save() does not update entity audience field #42

schultetwin opened this issue Apr 1, 2015 · 1 comment
Labels

Comments

@schultetwin
Copy link

To set context, I have a module that generates a node from an incoming email and associates it with a group based on the email address that it came in on. The flow looks something like this:

//(email arrives, and triggers drupal)
// Prepare node, populate fields
node_save($node);
foreach ($group_nodes as $gid => $group_node) {
  og_group('node', $gid, array('entity_type' => 'node', 'entity' => $node);
}
// At this point, $node->og_group_ref should be populated, but it is not.

(FYI, this is a modification I'm making to the og_mailinglist module).

In the og_group() source code, it specifically mentions that OgMembership::save() should update the entity in question.

My current solution is this:

    $entity_wrapper = entity_metadata_wrapper($entity_type, $entity);
    $items = $entity_wrapper->{$field_name}->value();
    $items[] = $group;
    $entity_wrapper->{$field_name}->set($items);

In OgMembership::save() after parent::save(). (Sorry, no patch at the moment).

@schultetwin
Copy link
Author

Updated sample solution to something that actually works.

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

No branches or pull requests

2 participants