Problem/Motivation

In order to track revisions in entity reference fields I applied patches from the following Entity Reference and Entity API issues: #1837650: Allow referencing a specific revision ID and #1788568: entity_metadata_wrapper does not load correct revisions. Unfortunately the patch from #12 #1788568-12: entity_metadata_wrapper does not load correct revisions introduces an infinite loop when used with Organic Groups. It appears to be caused by the addition of entity_load_single() within EntityDrupalWrapper->set() on line 781 of includes/entity.wrapper.inc.

My basic understanding is that when entity_load() is called to load a node that is group content, this in turn calls NodeController->attachLoad() which leads to entity_reference_field_load() being invoked for Organic Group reference fields. OG's Entity Reference behavior handler's load function OgBehaviourHandler->load() uses entity_metadata_wrapper() (see og/plugins/entityreference/behavior/OgBehaviorHandler.class.php:23) which gets us to EntityDrupalWrapper->set() and with the addition of entity_load_single() we loop back to entity_load().

Proposed resolution

I needed a quick fix and so I chose to address it in the OgBehaviorHandler by removing the call to entity_metadata_wrapper(). However, in doing so I removed the early return if a bundle was deleted functionality.

I'm not sure how or where to best address the infinite loop, whether to address it in OG or in Entity API? For now I'll include the patch for my quick, but incomplete, fix. Any advice or recommendations would be greatly appreciated. Many thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lwalley’s picture

Attached is the quick fix patch. Note that the check for deleted bundles is removed and therefore this patch may cause problems.

lwalley’s picture

amitaibu’s picture

Status: Active » Needs review

Correct status.
BTW, you can provide this as PR

mpotter’s picture

Using this successfully with the other revision patches in Open Atrium 2.

amitaibu’s picture

+++ b/plugins/entityreference/behavior/OgBehaviorHandler.class.php
@@ -20,12 +20,7 @@ class OgBehaviorHandler extends EntityReference_BehaviorHandler_Abstract {
+      list($id) = entity_extract_ids($entity_type, $entity);

As we still need this "early return",
Maybe you can try to extract also the bundle in entity_extract_ids() and check it is valid?