Last active
December 15, 2015 00:18
-
-
Save madeingnecca/5171501 to your computer and use it in GitHub Desktop.
DRUPAL 7 - get ID from entity
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 | |
// Method 1: get both id key and id value. Verbose way. | |
$entity_wrapper = entity_metadata_wrapper($entity_type, $entity); | |
$pri = $entity_wrapper->entityKey('id'); | |
$entity_id = $entity_wrapper->$pri->value(); | |
// Method 2: get only id value. More succint way. | |
list($entity_id) = entity_extract_ids($entity_type, $entity); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment