Last active
August 29, 2015 14:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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