Skip to content

Instantly share code, notes, and snippets.

@lpeabody
Last active August 29, 2015 14:05
Show Gist options
  • Save lpeabody/6122f533191c8cd7170b to your computer and use it in GitHub Desktop.
Save lpeabody/6122f533191c8cd7170b to your computer and use it in GitHub Desktop.
Sweet function for getting the revision list of an entity of a given type.
<?php
/**
* Get a revision id list for a particular entity.
*/
function _get_entity_revision_list($type, $entity) {
$info = entity_get_info($type);
if (!isset($info['revision table'])) {
// If this entity does not track revisions then return FALSE.
return FALSE;
}
if (!isset($info['entity keys']['revision'])) {
// If for whatever reason a revision table was defined, but no revision key
// then also return FALSE.
return FALSE;
}
$revisions = db_select($info['revision table'], 'r')
->fields('r', array($info['entity keys']['revision']))
->condition($info['entity keys']['id'], $entity->{$info['entity keys']['id']})
->execute()
->fetchAllAssoc($info['entity keys']['revision']);
return array_keys($revisions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment