relation entity cache d7

WebMaster's picture
  • Relation Entity Collector block not working with Entity Cache
  • The issue is that Entity Collector cannot pick any entities after the page is cached in Entity Cache.
  • A perfect description of this behaviour is at #1402860-37: Panelizer is incompatible with moderation I traced the issue down to the fact that when using Entity Cache, hook_entity_load() functions are only called when the entity is first loaded/cached. On subsequent loads from the cache, hook_entity_load() is not called, which is the expected behavior of Entity Cache as far as I can tell. Entity Cache does provide a hook, hook_entitycache_load() / hook_entitycache_TYPE_load() which lets you hook into and alter the entities that are loaded by Entity Cache (whether they are loaded from the DB or from the cache).
diff --git a/relation_entity_collector.module b/relation_entity_collector.module
index 18d9a36..d37a0af 100644
--- a/relation_entity_collector.module
+++ b/relation_entity_collector.module
@@ -114,6 +114,15 @@ function relation_entity_collector_entity_load($entities, $type) {
}

/**
+ * Implements hook_entitycache_load().
+ */
+function relation_entity_collector_entitycache_load($entities, $type) {
+ $entities_store = &drupal_static('relation_entities', array());
+ $entities_store += array($type => array()); + $entities_store[$type] += $entities;
+}
+
+/**
* The entity_collector form.
*/
function relation_entity_collector($form, &$form_state) {
Drupal documentation wiki style