diff --git a/entityreference_count.module b/entityreference_count.module index c4c77ce..d1b2c99 100644 --- a/entityreference_count.module +++ b/entityreference_count.module @@ -494,22 +494,28 @@ function entityreference_count_get_referenced_ids($entity, $counted_fields) { * implementation above for more info. */ function entityreference_count_references_update($entity_type, $entity, $delay = FALSE) { - if (!$entity_type || !isset($entity->type)) { + if (!$entity_type || !isset($entity)) { return; } + // Get the entity's info. + list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity); + // Get all the entity reference fields for this content type. - $entityreference_fields = field_read_fields(array('type' => 'entityreference', 'entity_type' => $entity_type, 'bundle' => $entity->type)); + $entityreference_fields = field_read_fields(array('type' => 'entityreference', 'entity_type' => $entity_type, 'bundle' => $bundle)); - // If there are no entity references for this content type then there is nothing to count. + // If there are no entity references for this content type then there is + // nothing to count. if (empty($entityreference_fields)) { return; } - // Get all the entity reference fields for this content type that are counted by a entityreference count field. + // Get all the entity reference fields for this content type that are counted + // by a entityreference count field. $counted_fields = entityreference_count_get_counted_entityreference_fields($entity_type, $entityreference_fields); - // If there are no entity references being counted for this content type then there is nothing to count. + // If there are no entity references being counted for this content type then + // there is nothing to count. if (empty($counted_fields)) { return; }