You are here

function _makemeeting_clear_referencing_entity_cache in Make Meeting Scheduler 7.2

Invalidate referencing entities caches.

Recursive function clearing the cache for all the entities that references the given one using the entityreference module.

Parameters

$entity_type:

$entity_id:

1 call to _makemeeting_clear_referencing_entity_cache()
_makemeeting_clear_related_entity_cache in ./makemeeting.module
Invalidate related entity caches.

File

./makemeeting.module, line 237
Hooks and field implementations

Code

function _makemeeting_clear_referencing_entity_cache($entity_type, $entity_id) {
  $cleared =& drupal_static(__FUNCTION__, array());

  // Avoid the cache to be cleared twice for the same entity.
  if (!empty($cleared[$entity_type][$entity_id])) {
    return;
  }
  $cleared[$entity_type][$entity_id] = TRUE;

  // Get the entity bundle to retreive the field that can reference this kind
  // of entities.
  $entity = entity_load_single($entity_type, $entity_id);
  list(, , $bundle) = entity_extract_ids($entity_type, $entity);
  $fields_referencing = _makemeeting_clear_referencing_fields($entity_type, $bundle);

  // For each referencing field, get the entities that references the current
  // entity using the field and clear their cache.
  foreach ($fields_referencing as $field_name) {
    $query = new EntityFieldQuery();
    $query
      ->fieldCondition($field_name, 'target_id', $entity_id);
    foreach ($query
      ->execute() as $referent_entity_type => $referent_entities) {
      foreach ($referent_entities as $referent_entity_id => $referent_entity) {
        _makemeeting_clear_related_entity_cache($referent_entity_type, $referent_entity_id);
      }
    }
  }
}